gpt4 book ai didi

html - 删除不需要的水平滚动(水平滚动来自哪里?)

转载 作者:行者123 更新时间:2023-12-05 05:04:42 25 4
gpt4 key购买 nike

我注意到我的 React 应用程序有一个不需要的水平滚动条。我看到如果我注释掉 <About/>组件然后滚动消失。不确定为什么要添加它。如果我添加 overflow-x: hidden 它就会消失至 App.css但这似乎不是正确的解决方案。

此外,我看到了 <About/> = BLUE 组件出现在 RED 部分。我无法理解为什么会这样。

感谢任何帮助。

这些是文件和 Screenshot :

App.js

import React from "react";
import "./App.css";
import "bootstrap/dist/css/bootstrap.min.css";
import Landing from "./Components/Landing";
import About from "./Components/About";
function App() {
return (
<div className="App">
<Landing />
<About />
</div>
);
}
export default App;

App.css

.App {
height: 100vh;
width: 100vw;
max-width: 900px;
padding: 1rem;
background-color: lightpink;
}

登陆.js

import React from "react";
import "./Landing.css";

function Landing() {
return (
<div className="LandingContainer"></div>
}
export default Landing;

登陆.css

.LandingContainer {
height: 100%;
width: 100%;
background-color: lightgreen;
}

About.js

import React from "react";
import "./About.css";

function About() {
return (
<div className="MainAboutContainer"></div>
}
export default About;

About.css

.MainAboutContainer {
background-color: lightblue;
width: 100%;
height: 100%;
text-align: center;
}

最佳答案

您是否启用了任何其他 css?

如果没有,请尝试在您的 App.css 中添加以下内容:

*, *::before, *::after {
box-sizing: inherit;
}

html {
/* this makes sure the padding and the border is included in the box sizing */
box-sizing: border-box;
overflow-y: hidden;
}

html body {
padding: 0;
margin: 0;
overflow-y: inherit;
}

此外,您不应该将 height: 100% 添加到您的 LandingAbout 元素,它会使您的应用程序的高度加倍.

编辑

试试这个,它会消除水平滚动和奇怪的填充问题:

应用程序.css

*, *::before, *::after {
box-sizing: inherit;
}

html {
/* this makes sure the padding and the border is included in the box sizing */
box-sizing: border-box;
overflow-y: hidden;
}

html body {
padding: 0;
margin: 0;
overflow-y: inherit;
}

.App {
height: 100vh;
width: 100vw;
max-width: 900px;
padding: 1rem;
background-color: lightpink;
}

登陆.css

.LandingContainer {
width: 100%;
height: 100%;
background-color: lightgreen;
}

About.css

.MainAboutContainer {
width: 100%;
height: 100%;
background-color: lightblue;
text-align: center;
}

关于html - 删除不需要的水平滚动(水平滚动来自哪里?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60923203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com