使锚标签中的图像居中 [英] Centering an image that is in an anchor tag
问题描述
我在锚标签中有一张图片,我需要将其居中.
I have an image in an anchor tag, and I need to center it.
我已经使用DOM检查器中遇到的这种技术设法做到了这一点: http://jsfiddle.net/m6e3m/
I have managed to do so using this technique that I just came across messing about in the DOM inspector: http://jsfiddle.net/m6e3m/
它使用:
display: table;
margin 0 auto;
我尝试使用:
display: block;
margin: 0 auto;
width: (?)px;
,但我发现它实际上并没有居中,除非我弄乱了很多宽度,因为锚标签的宽度似乎不太好(imo),这并不是很好,这就像基本上使用了边距-左.
but I found it wasn't actually centering it unless I messed with the width a lot which isn't really very good as anchor tag widths seem to not work as well (imo), it was like basically using a margin-left.
对您是否曾经使用过此功能或发现更好的显示技术感到好奇:IE 7及更高版本不支持表格
Curious as to whether any of you have used this before or found an even better technique as display: table isn't supported on IE 7 and back
推荐答案
您可以在#container上使用text-align: center;
将其中的元素居中.
此处的示例: http://jsfiddle.net/m6e3m/3/
You can use text-align: center;
on the #container to center elements within it.
Example here: http://jsfiddle.net/m6e3m/3/
这篇关于使锚标签中的图像居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!