回答
我已經爲你做了一個演示並更正了你的代碼。 做檢查此鏈接:https://jsfiddle.net/djmayank/qsmpbs9d/
HTML:
<div id= "header">
</div>
CSS:
body {
margin: 0;
}
#header {
background-color: red;
height:5px;
width:100%;
-webkit-background-size: contain;
-moz-background-size: contain;
-o-background-size: contain;
background-size: contain;
padding-bottom: 9%;
background-repeat: no-repeat;}
希望它能幫助。
謝謝,我確實使用過你寫過的東西,但它不起作用,我的div看起來像這樣:
它應該檢查https://jsfiddle.net/djmayank/qsmpbs9d/2/ – djmayank
仍然一樣:(我使用的圖像,所以我不知道如果問題來自於此? – user8423460
很可能您的瀏覽器正在爲您的項目添加默認css,從而爲事物以及其他內容添加填充/邊距。我通常把resets
放在我的css文件的頂部,它清除了所有默認的CSS。那人很多用一個流行的CSS復位是埃裏克斯復位:
將這個在你的CSS文件,你的頭的頂部應全寬
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
display: block;
}
body {
line-height: 1;
}
ol, ul {
list-style: none;
}
blockquote, q {
quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
content: '';
content: none;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
謝謝,我確實使用了你寫的但是沒有工作,我的div看起來像這樣:
- 1. Full Width CSS - Responsive
- 2. HorrizontalScrollView Full Width
- 3. ion-nav-buttons full width
- 4. jssor:bug in full-width-slider.html
- 5. Rails Bootstrap Full Width Jumbotron
- 6. Wordpress Full Width Footer not working
- 7. Xcode Storyboard New Item Full Width and Height
- 8. CSS body and other divs not full full
- 9. Width = Parent Width CSS3
- 10. width/border-width(CSS)
- 11. img <a href> link stretches to full width of parent div instead of only covering img
- 12. $(window).width()vs $(document).width()
- 13. Full height div
- 14. Facebook Page Feed - Full Height
- 15. JavaScript max-width removeAttribute
- 16. Flex需要澄清:width,min(max)Width,explicitWidth,explicitMin(Max)Width,measuredWidth,measuredMinWidth,percentWidth
- 17. 可能使用width = device-width和meta name =「viewport」content =「width = 1024」?
- 18. ListView.GridViewColumn(*)width
- 19. asp.net mvc display header with header
- 20. RewriteCond和Full QUERY_STRING
- 21. Full emulation esme
- 22. Preg match full stop
- 23. Ajax.BeginForm force full postback
- 24. PostgreSQL:VACUUM FULL或CLUSTER?
- 25. GoogleAnalyticsTracker Store full
- 26. full calendar draggable
- 27. Java Full Screenshot
- 28. UpdatePanel Full Postback
- 29. CSS Header Image「Stacked」
- 30. Bootstrap 3 .control-label width?
把你的'html'代碼。 –
的HTML代碼?你必須缺少一些東西 – djmayank
標題部分: –
user8423460