搜索
首页web前端css教程重置 CSS 和规范化 CSS 之间的区别?

Difference between resetting and normalizing CSS?

开发人员希望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.

Difference between normalizing and resetting?

在使用CSS时,开发人员可能会遇到一些问题,例如在不同的浏览器中可能会有不同的标题字体和大小等。顶部和底部的边距可能不同,还有默认的填充。这时重置和规范化就发挥作用了,它们使默认的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 websites look more legible. For example, 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 due to different browser styles.

注意 - Internet Explorer不支持inherit属性,这就是为什么继承的值不会被应用,且在Internet Explorer上会影响用户界面。在使用Internet Explorer时,重置将帮助我们解决这个问题。

示例 

让我们来看一个示例,演示如何重置默认的浏览器样式。

<!DOCTYPE html>
<html lang="en">
<head>
   <title>Example of resetting!!</title>
</head>
<body>
   <h1 id="Hi-welcome-to-another-tutorial">Hi welcome to another tutorial</h1>
   <h3 id="How-is-your-day-going">How is your day going?</h3>
   <h2 id="We-Are-learning-how-to-Reset-CSS">We Are learning how to Reset CSS</h2>
   <h4 id="It-will-reset-the-default-CSS-by-the-browser">It will reset the default CSS by the browser</h4>
</body>
</html>

The link that we imported will reset the default styles of the browser. The reset styles load before other styles and this leads to the removal of the browser’s default styles.

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中进行标准化

To improve the cross browser compatibility, we use the normalizing to the HTML element and replaces the reset in HTML. Normalizing is done so that the useful defaults are preserved by the browsers instead of erasing them all. Let’s look at the usage of the normalizing.

  • It standardizes the styles for a lot of elements in HTML.

  • Removes the bugs from common browsers.

  • 通过改进可用性,通过文档简要解释代码。

Example

以下是一个示例,用于理解规范化的概念。在这个示例中,我们导入了normalize,它不会重置浏览器的样式,但在所有浏览器中都会显示相同的输出,没有任何差异。

<!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 id="Hi-welcome-to-another-tutorial">Hi welcome to another tutorial</h1>
   <h1 id="How-is-your-day-going">How is your day going?</h1>
   <h2 id="We-Are-learning-how-to-Reset-CSS">We Are learning how to Reset CSS</h2>
   <h4 id="It-will-reset-the-default-CSS-by-the-browser">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.

标准化保留了有用的默认样式并删除了无用的样式,而重置则删除了浏览器的所有样式。在重置中,我们需要在重置浏览器后重新声明所有样式,而标准化将保留所需的样式并仅删除不需要的样式。标准化易于使用,是一种现代化的技术。

结论

There is no much difference between normalizing and resetting as the purpose of both is same which is to preserve the UI of a website and make it compatible to all browsers so the website looks the same in every browser. Both of them have a different approach and depends upon the user’s preference.

以上是重置 CSS 和规范化 CSS 之间的区别?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:tutorialspoint。如有侵权,请联系admin@php.cn删除
我们如何标记Google字体并创建Goofonts.com我们如何标记Google字体并创建Goofonts.comApr 12, 2025 pm 12:02 PM

Goofonts是由开发人员和设计师丈夫签名的附带项目,它们都是版式的忠实拥护者。我们一直在标记Google

永恒的Web开发文章永恒的Web开发文章Apr 12, 2025 am 11:44 AM

Pavithra Kodmad向人们询问了他们认为是关于网络开发的一些最永恒的文章的建议

与部分元素的交易与部分元素的交易Apr 12, 2025 am 11:39 AM

同一天发表了两篇文章:

使用JavaScript API的状态练习GraphQl查询使用JavaScript API的状态练习GraphQl查询Apr 12, 2025 am 11:33 AM

学习如何构建GraphQL API可能具有挑战性。但是您可以学习如何在10分钟内使用GraphQL API!碰巧的是,我得到了完美的

组件级CMS组件级CMSApr 12, 2025 am 11:09 AM

当一个组件生活在数据查询居住在附近的数据查询的环境中时,视觉组件与

将类型设置在圆上...带偏移路径将类型设置在圆上...带偏移路径Apr 12, 2025 am 11:00 AM

这里是Yuanchuan的一些合法CSS骗局。有此CSS属性偏移路径。曾几何时,它被称为Motion-Path,然后被更名。我

'恢复”在CSS中有什么作用?'恢复”在CSS中有什么作用?Apr 12, 2025 am 10:59 AM

Miriam Suzanne在Mozilla开发人员的视频中解释了该主题。

现代恋人现代恋人Apr 12, 2025 am 10:58 AM

我喜欢这样的东西。

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解锁Myrise中的所有内容
4 周前By尊渡假赌尊渡假赌尊渡假赌

热工具

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版