如何在CSS中设置文本的背景颜色?
问题描述:
>
想要的是绿色背景不要100%的页面宽度。
我想把它放在文本的后面。
Html:
What I want is for the green background not to be 100% of the page width. I want it just behind the text. Html:
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>
The Last Will and Testament of
Eric Jones</h1>
</body>
style.css:
style.css:
h1
{
text-align: center;
background-color: green;
}
答
a href =http://www.htmlhelp.com/reference/html40/inline.html>内嵌元素,例如< span>
。
Put the text in an inline element, such as a <span>
.
<h1><span>The Last Will and Testament of Eric Jones</span></h1>
然后在内联元素上应用背景颜色。
And then apply the background color on the inline element.
h1 {
text-align: center;
}
h1 span {
background-color: green;
}
内联元素与其内容一样大,因此应该为你。
An inline element is as big as its contents is, so that should do it for you.