jquery - 如何使用 div 在另一个内部创建彩色矩形框我添加了下面的图片以显示我想要做的示例
问题描述
//我已经添加了下面的图片在此处输入图片描述
解决方案
除了你需要使用 JavaScript 的边框颜色外,我认为这个片段几乎可以满足你的需要。
// random color
function cc () { return Math.round(Math.random() * 254); }
function color () {
return "rgb(" + [ cc(), cc(), cc() ] + ")";
}
var main = document.getElementById("main");
main.style.borderColor = color();
while (main.firstElementChild) {
main = main.firstElementChild;
main.style.borderColor = color();
}
div {
/* color omitted and it will assign with javascript */
border: 1px solid;
}
#main { width: 400px; height: 600px; position: relative; }
div > div {
width: 95%;
height: 95%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
<!-- changed the "class" attribute as "id" -->
<div id="main">
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
推荐阅读
- julia - 用于遍历具有值和索引的数组的简写 for 循环
- netlogo - 在 NetLogo 中构建和循环列表
- scenekit - SceneKit:粒子系统的停止动画
- java - 在启用片段之前无法启动自动完成活动
- python-3.x - 输入事件时不弹出工具提示
- ios - 如何在 LineChart 中为突出显示的值绘制圆圈
- javascript - 通过单击按钮拼接使用 DOM 呈现的数组(Vanilla Js)
- azure - 了解如何在 Azure AD 中使用范围进行用户授权
- python - Python selenium 浏览器 firefox
- c# - 如何在 Xamarin.iOS 中使用数据保护?