問題描述
我一直在查看 Facebook 和 Youtube 等許多網站的 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;
}
這很奇怪,因為在 chrome web 開發人員工具中刪除該塊不會影響頁面的布局.
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?
推薦答案
這是一種稱為 CSS 重置的常用技術.不同的瀏覽器使用不同的默認邊距,導致站點看起來不同的邊距.*
表示所有元素"(一個 通用選擇器),所以我們設置所有元素都具有零邊距和零填充,從而使它們在所有瀏覽器中看起來都一樣.
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 中是什么意思?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!