skip to Main Content

I want to create 3 columns with CSS but why can I only see 1 column instead of 3 with CSS?

.column {
  height: 100vh;
  overflow-y: auto;
  box-sizing: border-box;
  padding: 20px;
}

.column:first-child,
.column:last-child {
  width: 25%;
  min-width: 300px;
}

.column:nth-child(2) {
  width: 50%;
  min-width: 600px;
}
<div class="container">
  <div class="column">
    <!-- First column content -->
    col 1
  </div>
  <div class="column">
    <!-- Second column content -->
    col 2
  </div>
  <div class="column">
    <!-- Third column content -->
    col 3
  </div>
</div>

https://jsfiddle.net/v1947art/

3

Answers


  1. Because divs are block-level elements that will be displayed below each other by default. Add flexbox to the parent container:

    .column {
      height: 100vh;
      overflow-y: auto;
      box-sizing: border-box;
      padding: 20px;
    }
    
    .column:first-child,
    .column:last-child {
      width: 25%;
      min-width: 300px;
    }
    
    .column:nth-child(2) {
      width: 50%;
      min-width: 600px;
    }
    
    /* add flexbox to the parent */
    .container {
      display: flex;
    }
    <div class="container">
      <div class="column">
        <!-- First column content -->
        col 1
      </div>
      <div class="column">
        <!-- Second column content -->
        col 2
      </div>
      <div class="column">
        <!-- Third column content -->
        col 3
      </div>
    </div>
    Login or Signup to reply.
  2. your height is

    height: 100vh;
    which causes the columns to go down if you scroll down you will see the col2.If you
    still cant find it press ctrl+f then type col2 you will find it if you want to keep the 3 cols in same sight decrease the height

    Login or Signup to reply.
  3. You need below changes in your CSS

    .column {
      height: 100vh;
      overflow-y: auto;
      box-sizing: border-box;
      padding: 20px;
      float: left;
    }
    
    .column:first-child,
    .column:last-child {
      width: 25%;
    }
    
    .column:nth-child(2) {
      width: 50%;
    }
    <div class="container">
        <div class="column">
            <!-- First column content -->
        col 1
        </div>
        <div class="column">
            <!-- Second column content -->
        col 2
        </div>
        <div class="column">
            <!-- Third column content -->
        col 3
        </div>
    </div>
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search