【问题标题】:Normalize.css does not fully add reset to react appNormalize.css 未完全添加重置以响应应用程序
【发布时间】:2019-06-10 19:03:31
【问题描述】:

我在这里关注 Reacts 官方网站上的 instructions。我在我的src 目录的根目录中有一个index.css 文件设置,其中导入为:

@import-normalize;

然后我在我的 App 组件中导入 index.css 文件:

import '../../index.css';

class App {}

虽然样式表确实存在,但它只是部分加载重置而不是全部。我在文档中看不到添加/减去您想要的选项。您可以在下面看到添加的内容。现在将其与full reset 进行比较。

/*! normalize.css v9.0.1 | MIT License | github.com/csstools/normalize.css */

/* Document
 * ========================================================================== */

/**
 * 1. Correct the line height in all browsers.
 * 2. Prevent adjustments of font size after orientation changes in
 *    IE on Windows Phone and in iOS.
 */

html {
  line-height: 1.15; /* 1 */
}

/* Sections
 * ========================================================================== */

/**
 * Correct the font size and margin on `h1` elements within `section` and
 * `article` contexts in Chrome, Firefox, and Safari.
 */

h1 {
  font-size: 2em;
  margin: 0.67em 0;
}

/* Grouping content
 * ========================================================================== */

/**
 * 1. Add the correct box sizing in Firefox.
 * 2. Show the overflow in Edge and IE.
 */

hr {
  box-sizing: content-box; /* 1 */
  height: 0; /* 1 */
}

/**
 * 1. Correct the inheritance and scaling of font size in all browsers.
 * 2. Correct the odd `em` font sizing in all browsers.
 */

pre {
  font-family: monospace, monospace; /* 1 */
  font-size: 1em; /* 2 */
}

/* Text-level semantics
 * ========================================================================== */

/**
 * Add the correct text decoration in Edge, IE, Opera, and Safari.
 */

abbr[title] {
  text-decoration: underline;
  text-decoration: underline dotted;
}

/**
 * Add the correct font weight in Chrome, Edge, and Safari.
 */

b,
strong {
  font-weight: bolder;
}

/**
 * 1. Correct the inheritance and scaling of font size in all browsers.
 * 2. Correct the odd `em` font sizing in all browsers.
 */

code,
kbd,
samp {
  font-family: monospace, monospace; /* 1 */
  font-size: 1em; /* 2 */
}

/**
 * Add the correct font size in all browsers.
 */

small {
  font-size: 80%;
}

/* Embedded content
 * ========================================================================== */

/* Forms
 * ========================================================================== */

/**
 * Remove the margin in Safari.
 */

button,
input,
select {
  margin: 0;
}

/**
 * 1. Show the overflow in IE.
 * 2. Remove the inheritance of text transform in Edge, Firefox, and IE.
 */

button {
  text-transform: none; /* 2 */
}

/**
 * Correct the inability to style clickable types in iOS and Safari.
 */

button,
[type="button"],
[type="reset"],
[type="submit"] {
  -webkit-appearance: button;
}

/**
 * Correct the padding in Firefox.
 */

fieldset {
  padding: 0.35em 0.75em 0.625em;
}

/**
 * 1. Add the correct display in Edge and IE.
 * 2. Add the correct vertical alignment in Chrome, Firefox, and Opera.
 */

progress {
  vertical-align: baseline; /* 2 */
}

/**
 * Remove the inheritance of text transform in Firefox.
 */

select {
  text-transform: none;
}

/**
 * 1. Remove the margin in Firefox and Safari.
 * 2. Remove the default vertical scrollbar in IE.
 */

textarea {
  margin: 0; /* 1 */
}

/**
 * 1. Correct the odd appearance in Chrome and Safari.
 * 2. Correct the outline style in Safari.
 */

[type="search"] {
  -webkit-appearance: textfield; /* 1 */
  outline-offset: -2px; /* 2 */
}

/**
 * Correct the cursor style of increment and decrement buttons in Safari.
 */

::-webkit-inner-spin-button,
::-webkit-outer-spin-button {
  height: auto;
}

/**
 * Correct the text style of placeholders in Chrome, Edge, and Safari.
 */

::-webkit-input-placeholder {
  color: inherit;
  opacity: 0.54;
}

/**
 * Remove the inner padding in Chrome and Safari on macOS.
 */

::-webkit-search-decoration {
  -webkit-appearance: none;
}

/**
 * 1. Correct the inability to style clickable types in iOS and Safari.
 * 2. Change font properties to `inherit` in Safari.
 */

::-webkit-file-upload-button {
  -webkit-appearance: button; /* 1 */
  font: inherit; /* 2 */
}

/**
 * Remove the inner border and padding of focus outlines in Firefox.
 */

::-moz-focus-inner {
  border-style: none;
  padding: 0;
}

/**
 * Restore the focus outline styles unset by the previous rule in Firefox.
 */

:-moz-focusring {
  outline: 1px dotted ButtonText;
}

/* Interactive
 * ========================================================================== */

/*
 * Add the correct display in Edge and IE.
 */

details {
  display: block;
}

/*
 * Add the correct styles in Edge, IE, and Safari.
 */

dialog {
  background-color: white;
  border: solid;
  color: black;
  display: block;
  height: -moz-fit-content;
  height: -webkit-fit-content;
  height: fit-content;
  left: 0;
  margin: auto;
  padding: 1em;
  position: absolute;
  right: 0;
  width: -moz-fit-content;
  width: -webkit-fit-content;
  width: fit-content;
}

dialog:not([open]) {
  display: none;
}

/*
 * Add the correct display in all browsers.
 */

summary {
  display: list-item;
}

/* Scripting
 * ========================================================================== */

/* User interaction
 * ========================================================================== */

【问题讨论】:

    标签: css reactjs create-react-app norm


    【解决方案1】:

    有两个原因(第二个是主要原因)。

    1) 首先是由于 create react app 中的 browserslist 配置。 Postcss 使用浏览器列表配置来确定保留/删除哪些样式。最新版本的 CRA 使用此 browserslist 开发配置:

    "last 1 chrome version",
    "last 1 firefox version",
    "last 1 safari version"
    

    如果您将生产配置复制到开发中,您会看到添加了一些样式。例如,overflow: visible; 被添加到 Edge 和 IE 的 hr 元素中。如果您想更清楚地了解将包含哪些内容并且在项目中不太远,请运行构建,然后查看 static/css/*main.randomletters.chunk 块文件。

    2) Postcss-normalize doesn't actually point 在您链接的 necolas/normalize.css 样式表中。相反,它指向@csstools/normalize.css您注意到的许多差异都会存在。 postcss-normalize 的作者(谁共同创建了 normalize)说这个版本得到了更积极的维护,因为 necolas/normalize 版本包括“非修复”。我还没有深入了解它们是否实际上是不可修复的,但你可以在这里看到他所说的:https://github.com/csstools/normalize.css/issues/3。如果您安装了它,请随时yarn remove normalize.css

    【讨论】:

    • 感谢您的回复。那么有没有办法自己配置浏览器列表呢?
    • 你可以!如果您使用了 create-react-app,您应该会看到 package.json 中的配置,这是您需要更改的。 browserslist package 很简洁,因为您可以根据每个国家、世界等的浏览器使用统计数据或仅按特定浏览器版本将其定位为一般覆盖范围。如果我在一个需要最大覆盖率的项目中,我通常会发现使用[>1%, ie>=latestYouNeedToSupport] 就足够了。更多文档在这里:https://github.com/browserslist/browserslist.
    猜你喜欢
    • 2015-11-22
    • 2017-05-31
    • 2017-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    相关资源
    最近更新 更多