如何针对所有屏幕尺寸将网页上的图像居中
我的 HTML 有问题。我在互联网上进行了搜索,但仍然没有真正的答案。
我有一个包含一些图像的网站,我希望它们位于中间。现在,在我的屏幕上,它们位于中间,但那是因为我通过将它们移动到一侧来将它们放置在那里。当我的朋友们看它时,图像偏离了中心。
这是网站;如果您使用的是 13.5 英寸屏幕,它看起来会位于中间。
I'm having a problem with my HTML. I've searched all over the internet, but still no real answer.
I have a website with some images, and I want them to be in the middle. Now, on my screen they're in the middle, but that's because I've put them there by moving them to one side. When my friends to look at it, the image is off-center.
Here's the website; if you are on a 13.5" screen it will look to be in the middle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试这样的事情......
Try something like this...
text-align:center
将
text-align:center
样式应用于包含元素的元素将使这些元素居中。Thomas Shields 提到了这个方法
margin:0 auto
将
margin:0 auto
样式应用于块元素会将其置于其所在元素的中心。user1468562 提到了这一点method
Center 标签
我原来的答案是可以使用
今天仍然受到技术支持(9 年后更新此内容),但我建议使用上面包含的 CSS 替代方案。
您可以在此 jsfiddle 中查看这三个代码示例的实际效果。
我决定应该修改这个答案,因为我之前给出的答案已经过时了。当我建议它作为解决方案时,它已经被弃用了,这就是 9 年后现在避免使用它的更多理由。
text-align:center
Applying the
text-align:center
style to an element containing elements will center those elements.Thomas Shields mentions this method
margin:0 auto
Applying the
margin:0 auto
style to a block element will center it within the element it is in.user1468562 mentions this method
Center tag
My original answer was that you can use the
<center></center>
tag. To do this, just place the content you want centered between the tags. As of HTML4, this tag has been deprecated, though.<center>
is still technically supported today (9 years later at the time of updating this), but I'd recommend the CSS alternatives I've included above.You can see these three code samples in action in this jsfiddle.
I decided I should revise this answer as the previous one I gave was outdated. It was already deprecated when I suggested it as a solution and that's all the more reason to avoid it now 9 years later.
在您的具体情况下,您可以将包含的
a
元素设置为:JS Bin demo。
In your specific case, you can set the containing
a
element to be:JS Bin demo.
这是水平工作的
this works horizontally