Asterisk(*)在CSS选择器中做什么? [英] What does an Asterisk (*) do in a CSS selector?

查看:230
本文介绍了Asterisk(*)在CSS选择器中做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这个CSS代码,我跑了看看它做了什么,它概述了页面上的每个元素,

I found this CSS code and I ran it to see what it does and it outlined EVERY element on the page,

有人可以解释什么星号*在CSS中?

<style>
* { outline: 2px dotted red }
* * { outline: 2px dotted green }
* * * { outline: 2px dotted orange }
* * * * { outline: 2px dotted blue }
* * * * * { outline: 1px solid red }
* * * * * * { outline: 1px solid green }
* * * * * * * { outline: 1px solid orange }
* * * * * * * * { outline: 1px solid blue }
</style>


推荐答案

这是一个通配符,

例如,如果我想对整个页面上的每个元素应用margin,您可以使用:

For example, if I want apply margin to every element on my entire page you can use:

* {
    margin: 10px;
}

您还可以在子选择中使用此选项,例如,一个段落标签内所有元素的边距:

You can also use this within sub-selections, for example the following would add a margin to all elements within a paragraph tag:

p * {
    margin: 10px;
}

你的例子是做一些css欺骗来应用连续的边框和边距到元素给他们多个彩色边框。例如,由黑色边框包围的白色边框。

Your example is doing some css trickery to apply consecutive borders and margins to elements to give them multiple coloured borders. For example, a white border surrounded by a black border.

这篇关于Asterisk(*)在CSS选择器中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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