我在div中有一个h2元素。div宽150 to,但h2可能更宽,因此文本必须中断并转到下一行。问题是,即使文本中断,h2元素的背景色也不会中断,因此h2元素的背景色覆盖整个div。
有什么方法可以让H2的背景色只出现在文本下面吗?
示例:
<div>
<h2>This is a long text test</h2>
</div>
CSS
div {
background-color: green;
width: 150px;
height: 150px;
padding-top: 15px;
}
h2 {
back
我在一个网站上工作,中间使用一个960容器,现在唯一的问题是设计师在一些div上使用了不同的背景颜色。
所以我现在的代码是:
<div id="content">
<!-- the content needs to 960 on the width only the background need the full width of the page -->
<div class="whitebackground">
<!-- content