如何删除底部正文内的额外空白。

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

How to Remove Extra White Space inside Body at Bottom

问题

我正在创建一个基于文章的网站,但在<body>底部出现了一个空白空间。
这是问题所在:
[请查看底部的Footer lorem行。](https://i.stack.imgur.com/DAHEF.png)

这是代码,有人能解决吗?

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="scss.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
</head>

<body>
    <header>
        <div class="con1">

             <img src="https://lh3.googleusercontent.com/a/AAcHTtexpBPyQQMZKXRYF3APKZhGsVounjRCydXqOYv-ij6fCVo=s96-c-rg-br100"
                alt="">
            <nav>
                <a href="#">Home</a>
                <a href="#">About</a>
                <a href="#">Contact</a>
            </nav>
        </div>
        <div class="con2">
            <div class="ham_burger">
                <i class="fa-solid fa-bars"></i>
            </div> 

        </div>
    </header>
    <div class="maincontent">
        <div class="leftside">
            <h1>
                Hello,
            </h1>
            <h2>
                Lorem, ipsum dolor sit amet consectetur adipisicing elit. Exercitationem voluptatibus ut tempora voluptates dolorem perspiciatis dolor eum excepturi porro, ullam, nesciunt veritatis tenetur, cupiditate quidem.
            </h2>
        </div>
        <div class="rightside">
            <img src="https://jamesclear.com/wp-content/uploads/2023/05/atomic-habits-full-dots.png" alt="">
            <h3>Lorem ipsum dolor sit amet.</h3>
        </div>
    </div>
    <footer>
        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Cumque numquam necessitatibus asperiores unde enim rerum, ipsam, voluptas quibusdam non vitae consectetur sequi molestiae!
    </footer>
</body>

</html>

@import url("https://fonts.googleapis.com/css2?family=Maven+Pro:wght@400;500&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Maven+Pro:wght@400;500&family=Poppins:wght@300&display=swap");
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  border: 1px solid red;
}

html {
  height: 100%;
  width: 100%;
}

body {
  min-height: 100%;
}

header {
  position: relative;
  display: flex;
  height: 91px;
}

a {
  font-size: medium;
  text-decoration: none;
  font-family: "Maven Pro", sans-serif;
  color: black;
}

.con1 {
  z-index: 1;
  display: flex;
  background-color: white;
  height: inherit;
  justify-content: flex-start;
  align-items: center;
  width: 50%;
  gap: 3vw;
  padding-left: 6vw;
}
.con1 img {
  height: 47px;
}

.con2 {
  display: flex;
  justify-content: flex-end;
  height: inherit;
  background-color: white;
  padding-right: 6vw;
  align-items: center;
  width: 50%;
}

nav {
  display: flex;
  gap: 3vw;
}

.maincontent {
  display: flex;
  flex-wrap: wrap;
  height: 100%;
}

.leftside {
  background-color: red;
  display: flex;
  flex-direction: column;
  width: 50%;
  padding-left: 6vw;
  padding-top: 8vh;
}

.rightside {
  padding-top: 8vh;
  background-color: yellow;
  display: flex;
  flex-direction: column;
  width: 50%;
  align-items: center;
}
.rightside img {
  width: 37vw;
  height: auto;
}

@media screen and (max-width: 500px) {
  .maincontent {
    display: flex;
    flex-direction: column;
  }
  .leftside {
    width: 100%;
    justify-content: center;
  }
  .rightside {
    justify-content: center;
    text-align: center;
    width: 100%;
    height: 91 px;
    padding-top: 8vh;
    background-color: yellow;
    display: flex;
    flex-direction: column;
  }
}

我提供了CSS和HTML代码。我使用红色边框来检查问题的原因,似乎是占据了整个高度,但左侧和右侧组件没有。但找不到解决方法。

英文:

I am making an Article Based Website But getting A White space at bottom of <Body>
here is the Problem
See At the bottom Footer lorem line.

Here is the code can anyone solve it

&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;title&gt;Document&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;scss.css&quot;&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;header&gt;
&lt;div class=&quot;con1&quot;&gt;
&lt;img src=&quot;https://lh3.googleusercontent.com/a/AAcHTtexpBPyQQMZKXRYF3APKZhGsVounjRCydXqOYv-ij6fCVo=s96-c-rg-br100&quot;
alt=&quot;&quot;&gt;
&lt;nav&gt;
&lt;a href=&quot;#&quot;&gt;Home&lt;/a&gt;
&lt;a href=&quot;#&quot;&gt;About&lt;/a&gt;
&lt;a href=&quot;#&quot;&gt;Contact&lt;/a&gt;
&lt;/nav&gt;
&lt;/div&gt;
&lt;div class=&quot;con2&quot;&gt;
&lt;div class=&quot;ham_burger&quot;&gt;
&lt;i class=&quot;fa-solid fa-bars&quot;&gt;&lt;/i&gt;
&lt;/div&gt; 
&lt;/div&gt;
&lt;/header&gt;
&lt;div class=&quot;maincontent&quot;&gt;
&lt;div class=&quot;leftside&quot;&gt;
&lt;h1&gt;
Hello,
&lt;/h1&gt;
&lt;h2&gt;
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Exercitationem voluptatibus ut tempora voluptates dolorem perspiciatis dolor eum excepturi porro, ullam, nesciunt veritatis tenetur, cupiditate quidem.
&lt;/h2&gt;
&lt;/div&gt;
&lt;div class=&quot;rightside&quot;&gt;
&lt;img src=&quot;https://jamesclear.com/wp-content/uploads/2023/05/atomic-habits-full-dots.png&quot; alt=&quot;&quot;&gt;
&lt;h3&gt;Lorem ipsum dolor sit amet.&lt;/h3&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;footer&gt;
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Cumque numquam necessitatibus asperiores unde enim rerum, ipsam, voluptas quibusdam non vitae consectetur sequi molestiae!
&lt;/footer&gt;
&lt;/body&gt;
&lt;/html&gt;
@import url(&quot;https://fonts.googleapis.com/css2?family=Maven+Pro:wght@400;500&amp;display=swap&quot;);
@import url(&quot;https://fonts.googleapis.com/css2?family=Maven+Pro:wght@400;500&amp;family=Poppins:wght@300&amp;display=swap&quot;);
* {
padding: 0;
margin: 0;
box-sizing: border-box;
border: 1px solid red;
}
html {
height: 100%;
width: 100%;
}
body {
min-height: 100%;
}
header {
position: relative;
display: flex;
height: 91px;
}
a {
font-size: medium;
text-decoration: none;
font-family: &quot;Maven Pro&quot;, sans-serif;
color: black;
}
.con1 {
z-index: 1;
display: flex;
background-color: white;
height: inherit;
justify-content: flex-start;
align-items: center;
width: 50%;
gap: 3vw;
padding-left: 6vw;
}
.con1 img {
height: 47px;
}
.con2 {
display: flex;
justify-content: flex-end;
height: inherit;
background-color: white;
padding-right: 6vw;
align-items: center;
width: 50%;
}
nav {
display: flex;
gap: 3vw;
}
.maincontent {
display: flex;
flex-wrap: wrap;
height: 100%;
}
.leftside {
background-color: red;
display: flex;
flex-direction: column;
width: 50%;
padding-left: 6vw;
padding-top: 8vh;
}
.rightside {
padding-top: 8vh;
background-color: yellow;
display: flex;
flex-direction: column;
width: 50%;
align-items: center;
}
.rightside img {
width: 37vw;
height: auto;
}
@media screen and (max-width: 500px) {
.maincontent {
display: flex;
flex-direction: column;
}
.leftside {
width: 100%;
justify-content: center;
}
.rightside {
justify-content: center;
text-align: center;
width: 100%;
height: 91 px;
padding-top: 8vh;
background-color: yellow;
display: flex;
flex-direction: column;
}
}

I have given css and html code. I have used Red border to check what is causing the problem and it seems the body is taking full length but the component left side and right side isn't. But Cant find the solution .

答案1

得分: 0

以下是翻译好的部分:

  • 你的身体并没有你想象的那么高。

  • html 中移除宽度和高度属性。

  • body 具有 min-height: 100vh,并且将其设为 flex 容器。

  • .maincontent 中移除高度属性,而是添加 flex-grow: 1 以允许该元素扩展以填充剩余空间。

英文:

Your body isn't as high as you think there to begin with.

Remove width and height from html.
Make body have min-height: 100vh, and also make it a flex container.
Remove the height from .maincontent, and add flex-grow: 1 instead to allow the element to grow to fill the remaining space.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

@import url(&quot;https://fonts.googleapis.com/css2?family=Maven+Pro:wght@400;500&amp;display=swap&quot;);
@import url(&quot;https://fonts.googleapis.com/css2?family=Maven+Pro:wght@400;500&amp;family=Poppins:wght@300&amp;display=swap&quot;);
* {
padding: 0;
margin: 0;
box-sizing: border-box;
border: 1px solid red;
}
body {
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
position: relative;
display: flex;
height: 91px;
}
a {
font-size: medium;
text-decoration: none;
font-family: &quot;Maven Pro&quot;, sans-serif;
color: black;
}
.con1 {
z-index: 1;
display: flex;
background-color: white;
height: inherit;
justify-content: flex-start;
align-items: center;
width: 50%;
gap: 3vw;
padding-left: 6vw;
}
.con1 img {
height: 47px;
}
.con2 {
display: flex;
justify-content: flex-end;
height: inherit;
background-color: white;
padding-right: 6vw;
align-items: center;
width: 50%;
}
nav {
display: flex;
gap: 3vw;
}
.maincontent {
display: flex;
flex-wrap: wrap;
flex-grow: 1;
}
.leftside {
background-color: red;
display: flex;
flex-direction: column;
width: 50%;
padding-left: 6vw;
padding-top: 8vh;
}
.rightside {
padding-top: 8vh;
background-color: yellow;
display: flex;
flex-direction: column;
width: 50%;
align-items: center;
}
.rightside img {
width: 37vw;
height: auto;
}
@media screen and (max-width: 500px) {
.maincontent {
display: flex;
flex-direction: column;
}
.leftside {
width: 100%;
justify-content: center;
}
.rightside {
justify-content: center;
text-align: center;
width: 100%;
height: 91 px;
padding-top: 8vh;
background-color: yellow;
display: flex;
flex-direction: column;
}
}

<!-- language: lang-html -->

    &lt;header&gt;
&lt;div class=&quot;con1&quot;&gt;
&lt;img src=&quot;https://lh3.googleusercontent.com/a/AAcHTtexpBPyQQMZKXRYF3APKZhGsVounjRCydXqOYv-ij6fCVo=s96-c-rg-br100&quot;
alt=&quot;&quot;&gt;
&lt;nav&gt;
&lt;a href=&quot;#&quot;&gt;Home&lt;/a&gt;
&lt;a href=&quot;#&quot;&gt;About&lt;/a&gt;
&lt;a href=&quot;#&quot;&gt;Contact&lt;/a&gt;
&lt;/nav&gt;
&lt;/div&gt;
&lt;div class=&quot;con2&quot;&gt;
&lt;div class=&quot;ham_burger&quot;&gt;
&lt;i class=&quot;fa-solid fa-bars&quot;&gt;&lt;/i&gt;
&lt;/div&gt; 
&lt;/div&gt;
&lt;/header&gt;
&lt;div class=&quot;maincontent&quot;&gt;
&lt;div class=&quot;leftside&quot;&gt;
&lt;h1&gt;
Hello,
&lt;/h1&gt;
&lt;h2&gt;
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Exercitationem voluptatibus ut tempora voluptates dolorem perspiciatis dolor eum excepturi porro, ullam, nesciunt veritatis tenetur, cupiditate quidem.
&lt;/h2&gt;
&lt;/div&gt;
&lt;div class=&quot;rightside&quot;&gt;
&lt;img src=&quot;https://jamesclear.com/wp-content/uploads/2023/05/atomic-habits-full-dots.png&quot; alt=&quot;&quot;&gt;
&lt;h3&gt;Lorem ipsum dolor sit amet.&lt;/h3&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;footer&gt;
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Cumque numquam necessitatibus asperiores unde enim rerum, ipsam, voluptas quibusdam non vitae consectetur sequi molestiae!
&lt;/footer&gt;

<!-- end snippet -->

答案2

得分: 0

额外的白色空间出现在您的 body 标签底部是因为 .maincontent 类中的 flex-wrap: wrap; 属性。

在 body 标签的样式中,设置 min-height: 100%,这会告诉浏览器确保 body 标签的高度为 100%。

英文:

The extra white space at the bottom of your body tag is due to the flex-wrap: wrap; property in . maincontent class

And in the styling of body tag,set min-height: 100% which will tell the browser to make sure that body tag is 100% tall

huangapple
  • 本文由 发表于 2023年8月10日 21:07:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76876018.html
匿名

发表评论

匿名网友

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

确定