【问题标题】:Background image in Styles.css appearing in every react router pagesStyles.css 中的背景图像出现在每个 React 路由器页面中
【发布时间】:2023-01-21 00:53:08
【问题描述】:

创建了一个包含页面的文件夹,在每个页面中用于 react router,然后在 styles.css 中添加其中一个背景时,每个页面都将显示相同的背景。

我以这种方式分配了背景图像:

body {
height: 100vh;
background-image: url("../../assets/images/Brandnewlaptop.jpg"); 
background-size: cover; 
background-position: center;
background-repeat: no-repeat;
}

我想将该图像放在该页面中,在其余页面中指定不同的图像背景,但这反而使所有页面都获得了“Bradnewlaptop”背景。

【问题讨论】:

    标签: css reactjs react-router background


    【解决方案1】:

    在 React 中编写程序时,您设置了一个根元素以替换为您的代码,但由于根是 body 的子元素,因此无论您将根设置为什么,您赋予 body 的属性都会显示。您可以做的是将背景图像提供给您想要背景的组件中的顶部元素

    【讨论】:

      猜你喜欢
      • 2020-08-23
      • 2021-06-12
      • 1970-01-01
      • 2014-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-23
      • 1970-01-01
      相关资源
      最近更新 更多