當你給線條增加寬度時,文本對齊:居中不起作用,我該如何解決這個問題?
.line-center {
margin: 0;
padding: 0 10px;
background: #fff;
display: inline-block;
}
h2 {
text-align: center;
position: relative;
z-index: 2;
width: 200px;
}
h2:after {
content: "";
position: absolute;
top: 50%;
left: 0;
right: 0;
border-top: solid 1px red;
z-index: -1;
}
<h2><span class="line-center">Test</span></h2>
# # #由于已經給元素指定了寬度,因此可以使用H2 { margin:0 auto;}將左邊距和右邊距設置為相等(在包含元素內)
.line-center {
margin: 0;
padding: 0 10px;
background: #fff;
display: inline-block;
}
h2 {
text-align: center;
position: relative;
z-index: 2;
width: 200px;
margin: 0 auto;
}
h2:after {
content: "";
position: absolute;
top: 50%;
left: 0;
right: 0;
border-top: solid 1px red;
z-index: -1;
}
<h2><span class="line-center">Test</span></h2>
上一篇python 解析器設置
下一篇python 文本去空