Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why can I only see 1 column instead of 3 with Css?

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/

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading