移动视图中某些不同的情况下,div之间有白线。

huangapple go评论78阅读模式
英文:

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.

移动视图中某些不同的情况下,div之间有白线。

英文:

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.

移动视图中某些不同的情况下,div之间有白线。

答案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);
}

希望这对您有所帮助。 移动视图中某些不同的情况下,div之间有白线。

英文:

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. 移动视图中某些不同的情况下,div之间有白线。

答案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%;
}

&lt;div className={&quot;main&quot;}&gt;
  &lt;div className={&quot;main-middle-div&quot;}&gt;
    &lt;div style={{ padding: &quot;0px 20px&quot; }}&gt;test &lt;/div&gt;
  &lt;/div&gt;
  &lt;div className={&quot;main-bottom-div&quot;}&gt;
    &lt;div&gt;test&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

huangapple
  • 本文由 发表于 2023年3月23日 11:13:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75818961.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定