在什么条件下我们可以使用css * selector? [英] in what conditions we can use css * selector?

查看:147
本文介绍了在什么条件下我们可以使用css * selector?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在什么条件下我们可以使用css * selector?多少*选择器是有用的?



只能使css重置或破解

 code> * {margin:0; padding:0; } 

还是其他有效用途?有没有办法使用* selector来优化css使用* selector?



是否支持所有浏览器?

解决方案

当你想表达一个元素存在,但你不在乎它是什么时,它主要有用。例如:

  #mything * span {color:red; } 

选择内部的范围,但不直接跨越 / p>

当您使用 * 作为全局匹配时,您应该谨慎。因为它可以击中你的页面上的每一个(可能成千上万)元素,它一定没有优化; (例如 .thing * 或只是 * ),它使得最多的浏览器选择器引擎的工作比一个更简单的选择器比 .thing 更难。您可以使用一个 * 规则来重置,但使用这些规则并不是一个好主意。



(个人我有点反对 * {margin:0; padding:0;} 修复它影响的方式多于实际需要的元素;真正的问题边框元素'只是列表元素,< form> 真的。一些形式控件也看起来错了,删除了padding。)


in what conditions we can use css * selector? how much * selector is useful?

is it only to make css reset or hack

* { margin: 0; padding: 0; }

or it has other valid useful uses? is there a ways to use * selector to optimize css using * selector?

Is it supported in all browsers?

解决方案

It's mainly useful where you want to express that there's an element present, but you don't care what it is. For example:

#mything * span { color: red; }

selects spans inside mything, but not spans directly inside mything.

You should be sparing about when you use * as a global match. As it could hit every one of the (potentially thousands of) elements on your page it's certainly no optimisation; in particular when it's the last thing in a selector (eg. .thing * or just * alone) it makes most browser selector engines work much harder than an simpler selector like .thing. You can get away with one * rule for resets, but using loads of them isn't a good idea.

(Personally I'm somewhat against the * { margin: 0; padding: 0; } fix. It affects way more elements than it actually needs to; the real ‘problem margin elements’ are just the list elements and <form> really. Some form controls also look wrong with the padding removed.)

这篇关于在什么条件下我们可以使用css * selector?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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