Background image doesn't show for header

若如初见. 提交于 2019-12-20 07:09:34

问题


I have simple html page with body and header elements:

<body>
    <header class="logoBar"></header>
</body>

I try to add background image to header. If i do:

.logoBar {
   background:url('http://img704.imageshack.us/img704/2162/67726065.jpg') repeat-x center top;
}

It doesn't show image. But if i make:

body {
    background:url('http://img704.imageshack.us/img704/2162/67726065.jpg') repeat-x center top;
}

I see image. Why doesn't it work for header?

Thank you.


回答1:


Try setting a width and height on your header element's css.

.logoBar {
   width: 100%;
   height: 250px; <!-- Your image height goes here...
   background:url('http://img704.imageshack.us/img704/2162/67726065.jpg') repeat-x center top;
}



回答2:


You have to set a width and height for the header. If it has no content it will simply be 0px wide and 0px tall.

.logoBar {
   background:url('http://img704.imageshack.us/img704/2162/67726065.jpg') repeat-x center top;
   width: 900px;
   height: 300px;
}

Demo: http://jsfiddle.net/Zjczp/




回答3:


now define value of your class .logobar

as like this

.logobar{display:block;}

and define width and height according to @WDffy and @Cristy



来源:https://stackoverflow.com/questions/15969870/background-image-doesnt-show-for-header

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!