0

这可能是一个简单的问题。我有具有背景颜色的标题文本。文本停止时背景颜色停止。我希望背景填充容器的整个长度。

<body>

 <div class="container">
   <p><span style="color:#ffffff; font-size:30px; background-color:#e12025;">I want the background-   color stretched across the container</span>
 </div>

</body>

CSS:

body {
background-color:#e12025;
align:center;
font-family:sans-serif;
color:#000000;
font-size:28px;
}

.container {
background-color:#ffffff;
position:relative;
margin-left:auto;
margin-right:auto;
height:1785px;
width:900px;
border-style:none;
padding:10px;
}

这是一个例子: http: //mm2.co/background-color

4

2 回答 2

1

如果您希望容器中的所有内容在容器中“拉伸”,请移除容器中的填充:

.container {
    padding:10px; /* remove this */
}

如果您仍想在容器中保留顶部/底部填充,请改为执行以下操作:

   .container {
        padding:10px 0px; /* add the 0px */
   }

此外,您还需要显示跨度段落

添加/更改为此:

<span style="display:block;">text here..</span>

于 2013-08-28T01:05:16.573 回答
0

嗯……

.container {
    display: block;
}

?

于 2013-08-28T00:58:30.210 回答