我认为 :first-of-type 会影响第一个类型,在我的情况下是
<div class="box">I am the first box in div.center...</div>
如果我删除 <div class="top">
CSS 作品并添加绿色顶部边框。
但我需要<div class="top">
,那为什么如果<div class="top">
有它不工作呢?
<div class="main-wrap">
<div class="center">
<h3>Lorem Ipsum</h3>
<div class="top">XXX XXX XXXX</div>
<div class="box">I am the first box in div.center. Why no top border?</div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
</div>
.box {
width:100%;
height:30px;
margin:10px 0;
background-color:orange;
}
.main-wrap .center div.box:first-of-type {
border-top:4px solid green;
}
.box {
position:relative;
border-bottom:4px solid green;
}