背景颜色填充文本后面的顶部70px div

时间:2015-06-05 18:01:41

标签: html css

有没有更简单的方法来做到这一点。我只想要背景颜色填充div的顶部宽度,70px高和div的整个宽度,在这种情况下为400px。我能够破解出一个解决方案,但它看起来很难看。抱歉,我使用的是内联样式,因为我无法轻松地将新的CSS添加到6500页的网站中。

<div style="border: 1px solid #bbb;  padding:20px; width:400px; height:150px; float:left; margin-right:60px;">
    <div style="background:#cccccc; width:440px; height:40px; padding:0; position:relative; margin-left:-20px; margin-top:-20px;"></div>
    <div style="background:#cccccc; width:420px; height:30px; padding-left:20px; position:relative; margin-left:-20px; margin-top:-20px;">
        <p><b>To learn more:</b></p>
    </div>
    <p><a href="#" class="btn btn-primary">Contact a sales rep</a></p>
</div>

JS Fiddle

1 个答案:

答案 0 :(得分:3)

您可以使用linear-gradient

background: #eeeeee; /* Old browsers */
background: -moz-linear-gradient(top,  #eeeeee 0%, #eeeeee 70px, #ffffff 70px, #ffffff 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(70px,#eeeeee), color-stop(70px,#ffffff), color-stop(100%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top,  #eeeeee 0%,#eeeeee 70px,#ffffff 70px,#ffffff 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top,  #eeeeee 0%,#eeeeee 70px,#ffffff 70px,#ffffff 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top,  #eeeeee 0%,#eeeeee 70px,#ffffff 70px,#ffffff 100%); /* IE10+ */
background: linear-gradient(to bottom,  #eeeeee 0%,#eeeeee 70px,#ffffff 70px,#ffffff 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */

http://www.colorzilla.com/gradient-editor/生成的代码