[英]CSS div design nth-child
这是一个例子。 您可以尝试此代码。 经过充分测试。 希望对您有帮助。
HTML:
<div>test1</div>
<div>test2</div>
<div>test3</div>
<div>test4</div>
<div>test5</div>
<div>test6</div>
<div>test7</div>
<div>test8</div>
<div>test9</div>
<div>test10</div>
<div>test11</div>
<div>test12</div>
CSS:
div{
width: 25%;
float:left;
border:1px solid #ccc;
box-sizing: border-box;
text-align:center;
}
div:nth-child(1), div:nth-child(2){
width: 100%;
}
div:nth-child(3), div:nth-child(4){
width: 50%;
}
演示:
您编写的任何CSS规则都必须用代数表示。
an + b-1
需要明确的是,除非使用JS,否则从HTML / DOM到CSS不会传递任何逻辑。
但是,在音乐会中使用:nth-child()和:nth-last-child()可能会变得非常复杂。
听起来您正在寻找的是这样的:
div{
width: 25%
}
div:nth-of-type(1), div:nth-of-type(2){
width: 100%;
}
div:nth-of-type(3), div:nth-of-type(4){
width: 50%;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.