【发布时间】:2015-12-04 13:48:35
【问题描述】:
我有一个容器,我想让h2 看起来与中心对齐,后面有一条细线。我不能做的是让线在h2 框后面。无论我尝试什么,它都会越过 h2 框。
任何帮助表示赞赏。
<div class="wrapper">
<div class="section-header">
<h2>H2 needs to be centered</h2>
<div class="line-section-header"></div>
</div>
</div>
我使用的css是:
h2 {
font-family: 'Open Sans', Arial, sans-serif;
font-family: 20px;
font-weight: 700;
text-transform: uppercase;
width: 140px;
color: #3F3F3F;
background-color: white;
padding: 5px 10px;
border: 1px solid #D3D3D3;
text-align: center;
margin: 0 auto;
z-index: 999;
}
.wrapper {
margin: 0 auto;
width: 980px;
height: 1000px;
background-color: #white;
}
.section-header {
width: 100%;
height: auto;
background-color: white;
float: left;
position: relative;
}
.line-section-header {
width: 100%;
height: 1px;
background-color: #D3D3D3;
margin-top: 15px;
position: absolute;
}
【问题讨论】:
-
要使
z-index工作,您需要提供元素position: relative|absolute|fixed。 -
请HTML然后我们可以帮助:)
-
请发布您当前拥有的 HTML 代码,并让我们知道您尝试的一些步骤。然后,我们可以努力让您朝着正确的方向前进。
-
嗨@AjayMakwana 有一段html和css。 @user3262111 我试图绝对定位
h2后面的线并将h2索引设置为一个高数字,这样它就会超过细线,但它没有用,线一直穿过@ 987654331@块。 -
大家好,你们真的帮助了我。太感谢了!祝大家有美好的一天。
标签: html css z-index positioning