CSS:" display:auto;" ;? [英] CSS: "display: auto;"?
问题描述
几个CSS属性给出的 auto
选项真的很有用。但是, display
属性似乎没有。我希望这可以将 display
属性设置为浏览器默认值,具体取决于标签;例如,< div>
将重置为 display:block;
,但是 ; span>
将重置为 display:inline;
。
- 是否有
显示:自动
等同于我错过了? - 如果没有,为什么不?
- 最优雅的解决方法是什么? (我以编程方式,特别是用jQuery。)
/ p>
$('element')。css('display','');
这将设置显示
例如:
< span>< / span>
$('span')。css('display','none');
$('span')。css('display','');
会导致 span
但是:
span {display:block}
< span>< / span>
$('span')。css('display','none');
$('span')。css('display','');
会导致 span
c $ c> display:block 。
这不是问题:事实上,它几乎总是想要的结果。
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;
.
- 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.)
You should use:
$('element').css('display','');
That will set display
to whatever is the default for element
according to the current CSS cascade.
For example:
<span></span>
$('span').css('display','none');
$('span').css('display','');
will result in a span
with display: inline
.
But:
span { display: block }
<span></span>
$('span').css('display','none');
$('span').css('display','');
will result in a span
with display: block
.
This is not a problem: in fact, it's almost always the desired result.
这篇关于CSS:" display:auto;" ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!