How to center a header image

与世无争的帅哥 提交于 2019-12-21 21:17:55

问题


I have a problem. The answers to other people questions didn't solve my problem.

It's about image in my header, here's the code:

HTML

<div id="site">

    <div id="header">
        <img class="center" src="http://i.imgur.com/jfDhpP5.png"/>    
    </div>

    <div id="mainNav">
        <li><a href="#">one</a></li>
        <li><a href="#">two</a></li>
        <li><a href="#">three</a></li>
        <li><a href="#">four</a></li>
    </div>

</div>

CSS

#container{
    width: 1000px;
    margin: 1em auto;
}

#header{
    display: block;
    width: 1000px;
    margin: 0 auto;
}

body{    
    background-color: grey;
    color: black;
    font-family: sans-serif;
}

img.center{
    text-align:center;
    margin: 0 auto;
    padding:0px;
}

I also try this:

div#pictures {
  text-align: center;
}

also not working... checked in firefox and IE, the newest versions.... o.O

Please help!


回答1:


CSS for header

width:100%;
text-align:center;

CSS for your img

display:inline-block;
margin: 0 auto;

See example here

That said, merely having text-align:center; on your header should be find, as in here



来源:https://stackoverflow.com/questions/20149206/how-to-center-a-header-image

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