Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
223 views
in Technique[技术] by (71.8m points)

html - CSS: Can I fit a container to a long/overflowing image?

One of my first css intensive projects, having trouble getting everything lined up how I'd want it to.

How it is and what I want to achieve

The second section is ignoring the overblown 600% image and going right after the previous container (obviously). I tried setting the .container-stars height to 600%, but that does literally nothing. Tried using px or vh units, but it messes with the SVG paths, where they ignore the absolute top: 0; and move to the middle (I imagine it's because of the height: 100% somehow, but I can't set it to specific units because then it wouldn't be responsive anymore)

When I set the .container-stars to height: 600vh

.container-stars {
  position: relative;
  width: 100vw;
  height: 100%;
  margin-top: 20%;
  background: linear-gradient(to bottom, $background 5%, white 40%, transparent 100%, $background 90%);
  .path_left {
    top: 0;
    left: 0;
    width: 45%;
    height: 100%;
    fill: $background;
  }
  .path_right {
    position: absolute;
    width: 45%;
    height: 100%;
    top: 0;
    right: 0;
    transform: scaleX(-1);
    fill: $background;
  }
  .img_stars {
    position: absolute;
    background-image: url('/img/stars-1654074_1920.jpg');
    top: 0;
    left: 0;
    width: 100%;
    height: 600%;
    repeat: repeat-y;
    z-index: -1;
  }
}

#content {
  position: relative;
  width: 100vw;
  margin-top: 0%;
  h2 {
    position: absolute;
    font-family: $primary-font;
    font-size: calc(2vw + 0.5rem);
    top: 0;
    background: green;
    display: block;
    transform: translate(0, 50%);
    color: #fff;
  }
}
<section class="container-stars">
  <svg class="path_left" width="450" height="600" viewBox="0 0 450 600">
      <path d="M 0 600 C 260 327 202 133 450 0 L 0 0"></path>
    </svg>
  <svg class="path_right" width="450" height="600" viewBox="0 0 450 600">
      <path d="M 0 600 C 260 327 202 133 450 0 L 0 0"></path>
    </svg>
  <div class="img_stars"></div>
</section>

<section id="content">
  <h2>...matter, energy, time and space came into being</h2>
</section>
question from:https://stackoverflow.com/questions/65926901/css-can-i-fit-a-container-to-a-long-overflowing-image

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...