CSS:" display:auto;&quot ;? [英] CSS: "display: auto;"?

查看:149
本文介绍了CSS:" display:auto;&quot ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几个CSS属性给出的 auto 选项真的很有用。但是, display 属性似乎没有。我希望这可以将 display 属性设置为浏览器默认值,具体取决于标签;例如,< div> 将重置为 display:block; ,但是 ; span> 将重置为 display:inline;


  1. 是否有显示:自动等同于我错过了?

  2. 如果没有,为什么不?

  3. 最优雅的解决方法是什么? (我以编程方式,特别是用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;.

  1. Is there a display: auto equivalent I've missed?
  2. If not, why not?
  3. 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:&quot; display:auto;&quot ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆