CSS:“显示:自动;”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6556994/
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
CSS: "display: auto;"?
提问by jameshfisher
The auto
option that several CSS attributes give is really useful. However, there doesn't seem to be one for the display
attribute. I would expect this to set the display
attribute to the browser default depending on the tag; e.g., a <div>
would reset to display: block;
, but a <span>
would reset to display: inline;
.
auto
几个 CSS 属性提供的选项非常有用。但是,该display
属性似乎没有。我希望这会display
根据标签将属性设置为浏览器默认值;例如, a<div>
会重置为display: block;
,但 a<span>
会重置为display: inline;
。
- Is there a
display: auto
equivalent I've missed? - If not, why not?
- What's the most elegant workaround? (I'm working programmatically, specifically with jQuery.)
- 有没有
display: auto
我错过的等价物? - 如果没有,为什么不呢?
- 最优雅的解决方法是什么?(我正在以编程方式工作,特别是使用 jQuery。)
采纳答案by thirtydot
You should use:
你应该使用:
$('element').css('display','');
That will set display
to whatever is the default for element
according to the current CSS cascade.
根据当前的 CSS 级联,这将设置display
为默认值element
。
For example:
例如:
<span></span>
$('span').css('display','none');
$('span').css('display','');
will result in a span
with display: inline
.
将导致span
与display: inline
.
But:
但:
span { display: block }
<span></span>
$('span').css('display','none');
$('span').css('display','');
will result in a span
with display: block
.
将导致span
与display: block
.
This is not a problem: in fact, it's almost always the desired result.
这不是问题:事实上,它几乎总是想要的结果。
回答by Miles Libbey
In CSS3, there is an initial value. Perhaps try display: initial;
在 CSS3 中,有一个初始值。也许试试display: initial;
回答by Ryan
There is no display: auto
property in CSS, the valid values are here
display: auto
CSS 中没有属性,有效值在这里
The default value is display: inline
. See the display reference from MDN
默认值为display: inline
。请参阅来自 MDN 的显示参考
Why is there no auto value? Simply because the CSS definition for the rule. You should also see the CSS rules around specificity as outlined in this article
为什么没有自动值?仅仅是因为规则的 CSS 定义。您还应该看到本文中概述的关于特异性的 CSS 规则
I hope this helps.
我希望这有帮助。
回答by Kon
There's a inheritoption, which:
有一个继承选项,其中:
Specifies that the value of the display property should be inherited from the parent element
指定应该从父元素继承显示属性的值
Other than that, just don't set display at all and it'll default to whatever it defaults to. Also, if you programmatically set it to nothing, I believe it just follows the default behavior then:
除此之外,根本不要设置显示,它会默认为它默认的任何内容。此外,如果您以编程方式将其设置为空,我相信它只是遵循默认行为:
document.getElementById('myElement').style.display = '';
回答by Charming Prince
depending on the parent element and the tag element in question the browser can quickly adjust to suite it. Most effectively it's always good to use DTD standards in your HTML opening tag to declare other available properties for the display selector, otherwise it uses only "block" & "inline". consequently if DTD is declared, using a display: inline-block;
property would be best in this case.
根据父元素和有问题的标签元素,浏览器可以快速调整以适应它。最有效的做法是在 HTML 开始标记中使用 DTD 标准来声明显示选择器的其他可用属性,否则它只使用“块”和“内联”。因此,如果声明了 DTD,display: inline-block;
在这种情况下最好使用属性。