简体   繁体   English

尝试设置最大高度时出现 CSS3 问题:100vh;

[英]CSS3 issue while trying to set max-height: 100vh;

I would like to ask a question to solve an issue that I am facing while trying to build a website.我想问一个问题来解决我在尝试建立网站时遇到的问题。 I will mention now that I am a beginner and my issue may have a simple answer which I cannot see at the moment.我现在要提一下,我是初学者,我的问题可能有一个简单的答案,我目前看不到。

I am having an HTML with 2 sections.我有一个带有 2 个部分的 HTML。 The 2nd section contains 2 divs, one with an image and another with some text.第二部分包含 2 个 div,一个带有图像,另一个带有一些文本。 I have the text and the image placed one next to the other with display: flex; flex-wrap: wrap;我将文本和图像并排放置,并带有display: flex; flex-wrap: wrap; display: flex; flex-wrap: wrap; and the vh of the whole section is min-height: 100vh;整个截面的vh min-height: 100vh; , but the div with the text is bigger than 100vh... ,但带有文本的 div 大于 100vh ...

This is the picture with the issue.这是有问题的图片。 Please note that the picture is 100vh and the div with the text is slightly bigger.请注意,图片为100vh,带有文字的div略大。 图片为100vh,文字稍大。当我调整窗口大小时,这种变化越来越大。

https://github.com/StefanMartin92/Iulia-Martin-Photography-Website.git https://github.com/StefanMartin92/Iulia-Martin-Photography-Website.git

I am trying the make the whole section 100vh, but the div with the text is making it go crazy if I change the window size/resolution.我正在尝试将整个部分设为 100vh,但如果我更改 window 大小/分辨率,带有文本的 div 会使 go 变得疯狂。 Please help!请帮忙!

/* ABOUT SECTION */

.about {
  min-height: 100vh;
  display: flex;
  flex-wrap: wrap;
}
.about-text {
  flex: 2 1 40rem;
  justify-content: space-around;
  background: var(--background-color);
  color: white;
  padding: 3rem 6rem;
}
.about-text h3 {
  padding: 2rem 0rem;
  font-family: "Ruhl Medium";
  align-items: center;
}
.about-text h2 {
  font-family: "Vibes";
  padding: 2rem;
}
.about-image {
  flex: 1 1 40rem;
  max-height: 100vh;
  position: relative;
}
.about-image h5 {
  position: absolute;
  top: 20%;
  left: 50%;
  transform: translate(-50%, -20%);
  letter-spacing: 2rem;
}
.about-image img {
  width: 100%;
    height: 100%;
  object-fit: cover;      
}

HTML CODE HTML 代码

<section class="about">
  <div class="about-image">
    <h5>MINIMAL</h5>
    <img src="https://stefanmartin92.github.io/Iulia-Martin-Photography-Website/img/about-image.png" alt="portrait-picture">
  </div>
  <div class="about-text flex">
    <h2>Iulia Martin</h2>
    <div class="about-life">
      <h3>My Life</h3>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis reprehenderit nobis distinctio vel, earum sapiente, ullam fugiat deleniti dicta magni quos nam aliquam modi. Cumque esse nihil illo dolore fugit.</p>
    </div>
    <div class="about-work">
      <h3>My Work</h3>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis reprehenderit nobis distinctio vel, earum sapiente, ullam fugiat deleniti dicta magni quos nam aliquam modi. Cumque esse nihil illo dolore fugit.</p>
    </div>
    <div class="about-contact">
      <h3>Get in touch</h3>
      <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Perferendis reprehenderit nobis distinctio vel, earum sapiente, ullam fugiat deleniti dicta magni quos nam aliquam modi. Cumque esse nihil illo dolore fugit.</p>
    </div>
  </div>
</section>

min-height sets just that, the minimum height of an element. min-height设置元素的最小高度。 It can still be bigger if it needs to, and that it is bigger.如果需要,它仍然可以更大,并且更大。 I don't know what exactly you want for this, but if you want it to scroll you can use.我不知道你到底想要什么,但如果你想让它滚动你可以使用。

max-height: 100vh;
overflow: scroll

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

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