什么是“*”是什么意思在CSS? [英] What does "*" mean in CSS?

查看:169
本文介绍了什么是“*”是什么意思在CSS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找许多网站的CSS文件,例如Facebook和Youtube。



几乎所有人都看到这个代码:

  * {
margin:0;
padding:0;
}

很奇怪,因为在chrome web开发者工具中删除该块


b >解决方案

这是一种常见的技术,称为CSS重置。不同的浏览器使用不同的默认边距,导致网站的边距看起来不同。 * 表示所有元素(通用选择器) ),因此我们将所有元素设置为零边距和零填充,从而使它们在所有浏览器中看起来一样。


I have been looking at the CSS files for many websites like Facebook and Youtube.

In almost all of them I see this code:

* {
margin: 0;
padding: 0;
}

It is odd, as removing that block in chrome web developer tools doesn't affect the layout of the page.

What does this code mean, and when is it used and why?

解决方案

This is a common technique called a CSS reset. Different browsers use different default margins, causing sites to look different by margins. The * means "all elements" (a universal selector), so we are setting all elements to have zero margins, and zero padding, thus making them look the same in all browsers.

这篇关于什么是“*”是什么意思在CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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