在什么条件下我们可以使用css * selector? [英] in what conditions we can use css * selector?
问题描述
在什么条件下我们可以使用css * selector?多少*选择器是有用的?
只能使css重置或破解
code> * {margin:0; padding:0; }
还是其他有效用途?有没有办法使用* selector来优化css使用* selector?
是否支持所有浏览器?
当你想表达一个元素存在,但你不在乎它是什么时,它主要有用。例如:
#mything * span {color:red; }
选择内部的范围,但不直接跨越 / p> 当您使用 (个人我有点反对 in what conditions we can use css * selector? how much * selector is useful? is it only to make css reset or hack 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: selects spans inside mything, but not spans directly inside mything. You should be sparing about when you use (Personally I'm somewhat against the 这篇关于在什么条件下我们可以使用css * selector?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
*
作为全局匹配时,您应该谨慎。因为它可以击中你的页面上的每一个(可能成千上万)元素,它一定没有优化; (例如 .thing *
或只是 *
),它使得最多的浏览器选择器引擎的工作比一个更简单的选择器比 .thing
更难。您可以使用一个 *
规则来重置,但使用这些规则并不是一个好主意。
* {margin:0; padding:0;}
修复它影响的方式多于实际需要的元素;真正的问题边框元素'只是列表元素,< form>
真的。一些形式控件也看起来错了,删除了padding。)* { margin: 0; padding: 0; }
#mything * span { color: red; }
*
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.* { 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.)