英文:
White line between divs for some different mobile views
问题
I created a minimal reproduceable example where I took out all styling except the background color and a height so it can be easily visible. Can anyone explain why there is a white line between the divs? It seems to be random based on the screen size. This issue is in chrome and Edge. I have not checked other browsers yet. I first thought it was an issue with Chromes mobile viewer but the same problem exists in Edge. Does anyone know what is causing this or how to resolve it? Here is the code. When you go to this link, you can switch between mobile views to see the issue as shown in the image below.
英文:
I created a minimal reproduceable example where I took out all styling except the background color and a height so it can be easily visible. Can anyone explain why there is a white line between the divs? It seems to be random based on the screen size. This issue is in chrome and Edge. I have not checked other browsers yet. I first thought it was an issue with Chromes mobile viewer but the same problem exists in Edge. Does anyone know what is causing this or how to resolve it? Here is the code. When you go to this link, you can switch between mobile views to see the issue as shown in the image below.
答案1
得分: 1
以下是翻译好的内容:
那些白线的原因是您HTML的body
部分。添加这个全局重置可能有助于消除那些白线。
* { margin: 0; padding: 0; }
因此,您的CSS数据内容可能如下所示。
* {
margin: 0;
padding: 0;
}
.main-bottom-div {
min-height: 35vh;
background-color: rgb(1, 65, 99);
}
.main-middle-div {
height: 10vh;
background-color: rgb(1, 65, 99);
}
希望这对您有所帮助。
英文:
The cause of that white lines is the body
of your HTML. Adding this global reset may help you get rid of that white lines.
* {
margin: 0;
padding: 0;
}
So the content of your CSS data may look like this.
* {
margin: 0;
padding: 0;
}
.main-bottom-div {
min-height: 35vh;
background-color: rgb(1, 65, 99);
}
.main-middle-div {
height: 10vh;
background-color: rgb(1, 65, 99);
}
Hope this could help you in some ways.
答案2
得分: 0
以下是代码的翻译部分:
.main {
position: relative;
height: 100px;
background: rgba(1, 65, 99, 0.99);
}
.main-bottom-div {
height: 65%;
}
.main-middle-div {
height: 45%;
}
<div className={"main"}>
<div className={"main-middle-div"}>
<div style={{ padding: "0px 20px" }}>test </div>
</div>
<div className={"main-bottom-div"}>
<div>test</div>
</div>
</div>
英文:
I never found out why this is happening but the only solution I have found is to simply put the background color in the parent div and add a percentage to each child div like below.
.main{
position: relative;
height: 100px;
background: rgba(1, 65, 99, 0.99);
}
.main-bottom-div {
height: 65%;
}
.main-middle-div {
height: 45%;
}
<div className={"main"}>
<div className={"main-middle-div"}>
<div style={{ padding: "0px 20px" }}>test </div>
</div>
<div className={"main-bottom-div"}>
<div>test</div>
</div>
</div>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论