我无法编码1px水平分隔符行,中心显示的标识为纯CSS。应该看起来像这样: Divider with logo centered在CSS中使用居中徽标的分隔符 - 使用多个实例时出现奇怪的错误
多个实例存在问题:当我在单个页面上添加更多分隔符时,只有一个或两个分隔符会显示一行,其他分隔符只会显示该标识。
大约为中心的标志。有人在这里找到答案 - 但没有不客气,与多个实例发生错误:Divider with centred image in CSS?
这里是一个适合的解决方案进行的讨论,下面捣鼓。
CSS:
body {
margin: 0;
background: white;
}
header:after {
content: '';
display: block;
width: 100%;
height: 1px;
background: #ccc;
margin-top: -90px; /* Negative margin up by half height of logo + half total top and bottom padding around logo */
}
.logo {
position: relative; /* Brings the div above the header:after element */
width: 200px;
height: 100px;
padding: 40px;
margin: 0 auto;
background: white url("http://placehold.it/200x100") no-repeat center center;
}
.logo img {
display: block;
}
HTML:
<body>
<header>
<div class="logo">
</div>
<div class="logo">
</div>
<div class="logo">
</div>
</header>
</body>
小提琴: http://jsbin.com/delixecobi/edit?html,css,output
太棒了。谢谢!看起来工作得很好。这里是z-index集的小提琴 - 以防人们想要使用它:http://jsbin.com/dinoligaya/1/edit?html,css,输出 – nebaon
还有一件事:如何扩大线来覆盖100%的宽度?似乎比我想象的更复杂。 – nebaon
@nebaon这很简单。你需要另一个包装,并把它作为'位置:相对' –