CSS 如何将标题图像居中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20149206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to center a header image
提问by user3022396
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
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
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
也无法正常工作...检查了 Firefox 和 IE,最新版本.... oO
Please help!
请帮忙!
回答by SW4
CSS for header
CSS 为 header
width:100%;
text-align:center;
CSS for your img
CSS 为您 img
display:inline-block;
margin: 0 auto;
That said, merely having text-align:center;
on your header
should be find, as in here
也就是说,只要有text-align:center;
你就header
应该找到,就像在这里