我想要的是绿色背景正好在文本后面,而不是页面宽度的100%.以下是我当前的代码:
h1 {
text-align: center;
background-color: green;
}
<h1>The Last Will and Testament of Eric Jones</h1>
我想要的是绿色背景正好在文本后面,而不是页面宽度的100%.以下是我当前的代码:
h1 {
text-align: center;
background-color: green;
}
<h1>The Last Will and Testament of Eric Jones</h1>
将文本放入inline element,例如<span>
.
<h1><span>The Last Will and Testament of Eric Jones</span></h1>
然后在内联元素上应用背景色.
h1 {
text-align: center;
}
h1 span {
background-color: green;
}
内联元素的大小和它的内容一样大,所以应该可以做到这一点.
会产生一个空行;复制