HTML 的 <a></a> 标签默认显示类型是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13548225/
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
What is HTML's <a></a> tag default display type?
提问by Dylan Cross
I haven't been able to find anything that says what the default display is equivalent to in CSS's display properties. I ask, because whenever I attempt to add padding or margin to an <a>
tag, it doesn't add it, I have to add the display property of inline-block
for it to.
我在 CSS 的显示属性中找不到任何说明默认显示等效于什么的内容。我问,因为每当我尝试向<a>
标签添加填充或边距时,它不会添加它,我必须inline-block
为它添加显示属性。
I don't know if this is browser specific or not, but would the default display of it be inline
versus say inline-block
(I obviously know it's not inline-block
.
我不知道这是否是特定于浏览器的,但它的默认显示是inline
不是说inline-block
(我显然知道它不是inline-block
.
回答by BoltClock
It is always display: inline
by default. Horizontal margins, and padding on all sides should work without having to change its display
property.
它始终display: inline
是默认值。水平边距和所有边的填充应该可以工作,而不必更改其display
属性。
This remains true even in HTML5. If you are applying styles to an <a>
element that contains flow elements or any other elements that are represented in CSS as display: block
, you should set the <a>
itself to a proper block container type such as block
or inline-block
for its layout to work as intended.
即使在 HTML5 中也是如此。如果您将样式应用于<a>
包含流元素或在 CSS 中表示为 的任何其他元素的元素display: block
,您应该将其<a>
本身设置为适当的块容器类型,例如block
或inline-block
使其布局按预期工作。
回答by Salil Momin
It's INLINE by default. Inline-block is not supported in IE7.
默认情况下它是内联的。IE7 不支持内联块。
margin is not supported in Inline element. and only left & right padding is supported in INLINE element.
内联元素不支持边距。并且在 INLINE 元素中仅支持左右填充。