2015-06-05 125 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 */ 

代碼