简体   繁体   English

ReactJS 背景图像未显示

[英]ReactJS Background Image not Showing

The code inside the image below suppose give me the background.下图中的代码假设给了我背景。 But it did not work.但它没有用。 I don't get it why?我不明白为什么?

Image to the problem问题的图片

.sign-in-container does not get 100% elevation. .sign-in-container 没有 100% 提升。 Because React have Root and you component inside root div on DOM.因为 React 有 Root 并且你在 DOM 上的根 div 内有组件。 Root's height is not 100%.根的高度不是 100%。 It is "auto".它是“自动”。

You have to use "height: 100vh" instead of height: "100%" this project.您必须使用“高度:100vh”而不是高度:“100%”这个项目。

In your stylesheet you should reset the margin and padding of the html and body tags and set the height and width respectively to 100vh and 100vw like this在您的样式表中,您应该重置htmlbody标签的边距和填充,并将heightwidth分别设置为100vh100vw如下所示

* {
    margin: 0;
    padding: 0;
}

html, body {
    width: 100vw;
    height: 100vh;
}

#root {
    width: 100%;
    height: 100%;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM