開發人員希望HTML元素在每個瀏覽器上看起來都一樣,儘管這取決於每個瀏覽器的功能不同。當瀏覽器渲染HTML頁面時,它會套用自己的預設樣式。例如,標題標籤的大小和字體會根據瀏覽器的類型而異。這意味著標題可以具有邊距或額外的填充,而無需您編寫程式碼。
In this tutorial, we are going to have a look at how we can reset and normalize CSS and what is the difference between them.
在使用CSS時,開發人員可能會遇到一些問題,例如在不同的瀏覽器中可能會有不同的標題字體和大小等。頂部和底部的邊距可能不同,還有預設的填充。這時重置和規範化就發揮作用了,它們使預設的CSS在所有瀏覽器中更加一致,但關於使用哪種方法的爭論仍在進行中。讓我們詳細了解重置和規範化,以便確定它們之間的差異。
To avoid cross-browser differences, in this technique, CSS authors null all the styles of the browser by using CSS reset. Different browsers will have their own different user agent stylesheet; to make the web have their ownsifferent user agent stylesheet; to make the webk. you might have seen hyperlinks in most of the browsers are blue, and visited hyperlinks appear purple in color.
An example of default styles can be −
#font-weight: bold; font-size: 10px;
這些預設樣式適用於所有瀏覽器,儘管瀏覽器決定要套用哪種樣式。有些瀏覽器可能會套用額外的填充,有些可能會改變邊距,甚至有些可能會有不同的字體樣式。
CSS重置將強制瀏覽器將所有樣式重設為null,從而避免因瀏覽器的預設樣式而產生的差異。
Let’s look at the example where we set the weight and style of all the elements as same.
font-weight: inherit; font-style: inherit; font-family: inherit;
CSS developers find inconsistencies, as their websites look different in different browsers. The reset helps the default browser styles to be set to null and this eliminates the inconsistencies that might occur bue that mighters d
注意 - Internet Explorer不支援inherit屬性,這就是為什麼繼承的值不會被套用,且在Internet Explorer上會影響使用者介面。在使用Internet Explorer時,重置將幫助我們解決這個問題。
範例
<!DOCTYPE html> <html lang="en"> <head> <title>Example of resetting!!</title> </head> <body> <h1>Hi welcome to another tutorial</h1> <h3>How is your day going?</h3> <h2>We Are learning how to Reset CSS</h2> <h4>It will reset the default CSS by the browser</h4> </body> </html>
The above output will look the same on every browser as we used the reset in the code. The difference in the output will be minimal after using the reset.
在CSS中進行標準化
<!DOCTYPE html> <html lang="en"> <head> <title>Example of normalizing CSS</title> <link rel="stylesheet" href= "https://necolas.github.io/normalize.css/7.0.0/normalize.css"> </head> <body> <h1>Hi welcome to another tutorial</h1> <h1>How is your day going?</h1> <h2>We Are learning how to Reset CSS</h2> <h4>It will reset the default CSS by the browser</h4> </body> </html>
There is an ongoing debate among developers on which one to choose and which one is better for a smooth flow.
標準化保留了有用的預設樣式並刪除了無用的樣式,而重設則刪除了瀏覽器的所有樣式。在重設中,我們需要在重設瀏覽器後重新聲明所有樣式,而標準化將保留所需的樣式並僅刪除不需要的樣式。標準化易於使用,是一種現代化的技術。
結論
以上是重設 CSS 和規範化 CSS 之間的差異?的詳細內容。更多資訊請關注PHP中文網其他相關文章!