在这个Question中,我跟着w3d用户回答,但没有得到顶级div下的div。
CSS
div.demo {
display:table;
width:100%;
}
div.demo span {
display:table-cell;
text-align:center;
}
#under {
width:100px;
height:2px;
background-color:blue;
}
HTML
<div class="demo">
<span>Span 1</span>
<span>Span 2</span>
<span>Span 3</span>
</div>
<div class="demo">
<span><div id='under'></div></span>
<span><div id='under'></div></span>
<span><div id='under'></div></span>
</div>
答案 0 :(得分:1)
在id
下试用此css#under {
width:100px;
height:2px;
background-color:blue;
margin:0px auto; /*ADDED*/
}
注意:使用class而不是ID,因为您在单页中多次使用id。
这是一个有效的HTML
<div class="demo">
<div>Span 1</div>
<div>Span 2</div>
<div>Span 3</div>
</div>
<div class="demo">
<div><span class="under"></span></div>
<div><span class="under"></span></div>
<div><span class="under"></span></div>
</div>
这是CSS
div.demo {
display:table;
width:100%;
}
div.demo div {
display:table-cell;
text-align:center;
}
.under {
width:100px;
height:2px;
background-color:blue;
margin:0px auto;
display:block;
}
<强> DEMO HERE 强>
答案 1 :(得分:1)
我知道您已经接受了答案,但也许可以考虑使用border-spacing
和border-bottom
?
div.demo {
border-spacing: 75px 0;
display: table;
width: 100%;
}
div.demo span {
border-bottom: 2px solid blue;
display: table-cell;
text-align: center;
}
<div class="demo">
<span>Span 1</span>
<span>Span 2</span>
<span>Span 3</span>
</div>