2015-06-05 209 views
0

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

<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

回答

3

您可以使用linear-gradient。通过http://www.colorzilla.com/gradient-editor/

产生

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 */ 

代码