skip to Main Content

I would like to create a <div class="chapters"> that contains 3 <div class="chapter">, each 100vw wide.

I do not know why, but I can only see 2 of them (1st one is missing) while the web inspector show them all.

Here is my code:

.container {
  width: 100vw;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
}

.chapters {
  background-color: bisque;
  flex-direction: row;
  min-width: 100vw;
}
.chapters .chapter {
  min-width: 100vw;
  height: 100vh;
  background-color: red;
  border: 1px solid white;
}
<div class="container chapters">
  <div class="chapter"></div>
  <div class="chapter"></div>
  <div class="chapter"></div>
</div>

At the beginning, I did not use min-width for .chapter so my all 3 div were visible but they were 100/3 vw wide.

I tried to use width and not min-width for .chapter**s**, or use % instead of vw but nothing works. Besides, I tried to remove all others HTML elements, or to remove all my scripts but it does not change a thing.

2

Answers


  1. .container {
      width: 100vw;
      height: 100vh;
      display: flex;
      justify-content: flex-start; /* or flex-end */
      align-items: center;
    }
    
    .chapters {
      background-color: bisque;
      flex-direction: row;
      min-width: 100vw;
    }
    
    .chapters .chapter {
      min-width: 100vw;
      height: 100vh;
      background-color: red;
      border: 1px solid white;
    }
       <div class="container chapters">
    
            <div class="chapter"></div>
            <div class="chapter"></div>
            <div class="chapter"></div>
    
        </div>
    Login or Signup to reply.
  2. Disable shrinking on flex items. Minimal example:

    /* using 100% height instead of 100vh to avoid vertical scrollbar */
    
    html {
      height: 100%;
    }
    
    body {
      height: 100%;
      margin: 0;
    }
    
    .chapters {
      height: 100%;
      display: flex;
    }
    
    .chapter {
      flex-shrink: 0;
      width: 100%;
    }
    
    .chapter:nth-child(1) {
      background-color: red;
    }
    
    .chapter:nth-child(2) {
      background-color: green;
    }
    
    .chapter:nth-child(3) {
      background-color: blue;
    }
    <div class="container chapters">
      <div class="chapter"></div>
      <div class="chapter"></div>
      <div class="chapter"></div>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search