所以我正在为学校作业制作一个响应式设计,我试图将图像宽度居中。
我在photoshop中缩放图像,所以我不必为图像设置任何宽度或高度
这是我现在得到的但是这不起作用
<header>
<img src="afb%20/logo3.png" alt="logo3" width="" height="" />
</header>
header{
width: 100%;
margin-left: auto;
margin-right: auto;
}
有人可以帮帮我吗?真的需要这个!
提前致谢
答案 0 :(得分:3)
只需在标题CSS中设置text-align: center
。
您目前正在将标题宽度设置为100%,因此您的边距不适用。因为你的容器是100%宽并且没有文本对齐,所以img总是在左边对齐。
下面:
header { width: 100%; text-align: center; }
答案 1 :(得分:3)
.center{margin: 0px auto; display: block;}
<header><img src="updates_button.jpg" alt="logo3" class="center"></header>
答案 2 :(得分:0)
您可以为图像添加徽标类,并将CSS设置为:margin:0px auto; width:200px;
当然要替换图像宽度......