目录
Difference between normalizing and resetting?
在CSS中重置样式
示例 
在CSS中进行标准化
Example
结论
首页 web前端 css教程 重置 CSS 和规范化 CSS 之间的区别?

重置 CSS 和规范化 CSS 之间的区别?

Aug 19, 2023 pm 12:21 PM

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>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 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>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.

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

结论

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中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Java教程
1664
14
CakePHP 教程
1422
52
Laravel 教程
1316
25
PHP教程
1268
29
C# 教程
1240
24
Google字体可变字体 Google字体可变字体 Apr 09, 2025 am 10:42 AM

我看到Google字体推出了新设计(Tweet)。与上一次大型重新设计相比,这感觉更加迭代。我几乎无法分辨出区别

如何使用HTML,CSS和JavaScript创建动画倒计时计时器 如何使用HTML,CSS和JavaScript创建动画倒计时计时器 Apr 11, 2025 am 11:29 AM

您是否曾经在项目上需要一个倒计时计时器?对于这样的东西,可以自然访问插件,但实际上更多

HTML数据属性指南 HTML数据属性指南 Apr 11, 2025 am 11:50 AM

您想了解的有关HTML,CSS和JavaScript中数据属性的所有信息。

使Sass更快的概念证明 使Sass更快的概念证明 Apr 16, 2025 am 10:38 AM

在一个新项目开始时,Sass汇编发生在眼睛的眨眼中。感觉很棒,尤其是当它与browsersync配对时,它重新加载

我们如何创建一个在SVG中生成格子呢模式的静态站点 我们如何创建一个在SVG中生成格子呢模式的静态站点 Apr 09, 2025 am 11:29 AM

格子呢是一块图案布,通常与苏格兰有关,尤其是他们时尚的苏格兰语。在Tar​​tanify.com上,我们收集了5,000多个格子呢

如何在WordPress主题中构建VUE组件 如何在WordPress主题中构建VUE组件 Apr 11, 2025 am 11:03 AM

内联式模板指令使我们能够将丰富的VUE组件构建为对现有WordPress标记的逐步增强。

当您看上去时,CSS梯度变得更好 当您看上去时,CSS梯度变得更好 Apr 11, 2025 am 09:16 AM

我关注的一件事是Lea Verou&#039; s conic-Gradient()Polyfill的功能列表是最后一项:

静态表单提供商的比较 静态表单提供商的比较 Apr 16, 2025 am 11:20 AM

让我们尝试在这里造成一个术语:“静态表单提供商”。你带上html

See all articles