【问题标题】:CSS Margin not working in React typescript projectCSS Margin 在 React 打字稿项目中不起作用
【发布时间】:2021-08-05 05:56:45
【问题描述】:

CSS 边距在我的 react typescript 项目中不起作用

我的代码:

const Home: React.FC = () => {
return (
<div style={{ width: "100vw", background: "skyblue" }}>
  <div
    style={{
      background: "red",
      height: "100px",
      width: "100px",
      marginLeft: "100px",
    }}
  ></div>
</div>
);
};

Codesandbox link for this project

【问题讨论】:

  • 检查您的codesandbox.io/s/zealous-ives-rx48z?file=/src/App.css 文件。边距应用于所有带有!important 的元素,这不好。
  • 因为您在 App.css 中使用 * { margin: 0px !important;} 覆盖了此样式。
  • 好的,谢谢!不知道我怎么错过了???? @m4n0
  • @Hadiazeez 您应该使用 chrome 检查器工具来确定应用了哪些样式。
  • 好的,谢谢大佬! @Cyber​​shadow

标签: css reactjs typescript sass


【解决方案1】:

您的边距被margin: 0px !important 覆盖,这是在您的App.css 文件中声明的

【讨论】:

    猜你喜欢
    • 2021-09-11
    • 2020-01-30
    • 2019-12-16
    • 2016-06-16
    • 2018-12-25
    • 1970-01-01
    • 2014-02-16
    • 2018-11-23
    • 2023-04-07
    相关资源
    最近更新 更多