Placing semantic element at top of column - html

I have some long text that I want to put into 2 columns.
I have a separate semantic element (in this case a table) that I want to appear at the top of the 2nd column.
The table will be the width of one column and fixed height.
The length of the text is unknown.
If the text is short enough that it occupies less height than the table then it should remain entirely within the 1st column.
Is there a way to achieve this without splitting the text between multiple elements and without using javascript?
I've tried floating the table to the right within an element with column-count: 2 but this didn't work because it floats to the right of the column, not the entire container.
I've also tried floating the table to the right outside of the element with column-count: 2, but this didn't work because the text doesn't flow around the table and attempts to display in 2 columns across only part of the width of the container.
I looked at using CSS grid but this doesn't allow for non-rectangular regions.
Absolute positioning won't work as the text will overlap the table.
I tried letting the table go to the bottom of the column and then adding a negative top margin, but this causes it to overlap the text.
Desired result:
Are there any other options?
Pure CSS solutions only please, no javascript.
N.B. This html will be converted to PDF with PrinceXML

EDIT: didn't work in Chrome. Fixed with a transform: translateZ(0); (may repaint the first paragraph or something in Chrome)
It seems to be possible but only because your special element is fixed height (which doesn't happen in reality or let's say on screen. You control how it's printed so OK but… well)
➡️ Codepen
Solution combines:
absolute position for the special element (and fixed height)
padding top on container (thus element doesn't surimpose on another element). There's a lot of room on top of 1st column, alongside the special element.
negative margin on the first paragraph (so the 1st column now appears filled).
CSS3 columns takes care of the total height so we're good.
/* Not normalize'd here */
/* 10rem is the fixed height of the special element. Update values like 11rem, + or -10rem accordingly */
.col-2 {
position: relative;
columns: 2;
width: 40rem;
padding: 11rem 1rem 1rem 1rem;
background-color: lightyellow;
}
.col-2 p:first-of-type {
/* or ".col-2 aside + p, .col-2 p:first-child {}" */
margin-top: -10rem;
background-color: lightblue;
transform: translateZ(0); /* bugfix Chrome paragraph disappeared (some paint problem) */
}
.col-2 aside {
position: absolute;
top: 1rem;
right: 0;
display: flex;
justify-content: center;
align-items: center;
width: 50%;
height: 9rem; /* leaves room for 1rem of margin below */
font-weight: bold;
font-size: 1.5rem;
background-color: tomato;
}
.col-2 + * {
max-width: 60rem;
min-height: 20rem;
padding: 1rem;
background-color: #f5f5f5;
}
<!-- https://stackoverflow.com/questions/48342730/placing-semantic-element-at-top-of-column#48342730 -->
<h1>2 test cases in this pen (scroll)</h1>
<div class="col-2">
<p>Case 1: special element at the end of its container.<br>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil vitae a voluptatibus quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil vitae a voluptatibus quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil vitae a voluptatibus quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil vitae a voluptatibus quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
<aside>your element</aside>
</div>
<p>Rest of content Lorem, ipsum dolor sit amet consectetur adipisicing elit. Cumque similique blanditiis veritatis voluptatibus a ipsa possimus laboriosam ducimus excepturi! Culpa quidem dolores unde? Deleniti voluptatibus ab eligendi similique, magni optio. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Cumque similique blanditiis veritatis voluptatibus a ipsa possimus laboriosam ducimus excepturi! Culpa quidem dolores unde? Deleniti voluptatibus ab eligendi similique, magni optio. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Cumque similique blanditiis veritatis voluptatibus a ipsa possimus laboriosam ducimus excepturi! Culpa quidem dolores unde? Deleniti voluptatibus ab eligendi similique, magni optio. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Cumque similique blanditiis veritatis voluptatibus a ipsa possimus laboriosam ducimus excepturi! Culpa quidem dolores unde? Deleniti voluptatibus ab eligendi similique, magni optio. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Cumque similique blanditiis veritatis voluptatibus a ipsa possimus laboriosam ducimus excepturi! Culpa quidem dolores unde? Deleniti voluptatibus ab eligendi similique, magni optio. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Cumque similique blanditiis veritatis voluptatibus a ipsa possimus laboriosam ducimus excepturi! Culpa quidem dolores unde? Deleniti voluptatibus ab eligendi similique, magni optio. Lorem, ipsum dolor sit amet consectetur adipisicing elit. Cumque similique blanditiis veritatis voluptatibus a ipsa possimus laboriosam ducimus excepturi! Culpa quidem dolores unde? Deleniti voluptatibus ab eligendi similique, magni optio.</p>
<div class="col-2">
<aside>your element</aside>
<p>Case 2: special element at the beginning of its container.<br>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil vitae a voluptatibus quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil vitae a voluptatibus quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil vitae a voluptatibus quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Repudiandae dignissimos commodi accusantium nihil vitae a voluptatibus quibusdam fugiat unde, ea exercitationem illum omnis aut similique odit tenetur, non</p>
</div>

Related

Sidebar with sticky elements at top and footer fixed at bottom

I am trying to make a website layout with a header, sidebar, and main body. The main layout is a CSS grid. The sidebar has two elements in it:
The first (.sidebar .container .top) is a navigation area that is sticky, i.e. remains pinned to the top-left of the viewport when the user scrolls past the header.
The second (.sidebar .container .bottom) is a footer that should always be in the bottom left of the viewport.
In my code, the sticky navigation area works as intended, but I cannot get the .bottom element to do what I want:
If I set .sidebar .container to have height 100vh (as I have done below), then the sidebar behaves correctly once you scroll down, but when the page loads, the .bottom text is partially cut off.
If I set .sidebar .container to have height 100%, it stretches to match the length of the body text and the .bottom element isn't visible until you scroll all the way down.
I cannot use .bottom { position: fixed; } because this resets the width of .bottom, but I want the width to respond dynamically (note the use of fr units and max-width in the body styling).
How can I get the text at the bottom of the sidebar to float to the bottom of the viewport?
Here is my code (pardon the long lorem ipsum—it is necessary to show the scrolling behavior):
body {
display: grid;
grid-template-columns: 1fr 5fr;
max-width: 800px;
}
header {
grid-column: 1 / 3;
background-color: aqua;
}
.sidebar {
background-color: greenyellow;
}
.sidebar .container {
position: sticky;
top: 0;
height: 100vh;
display: grid;
grid-template-rows: 1fr auto;
}
main {
background-color: lightcoral;
}
<header>
<h1>Page title</h1>
</header>
<div class="sidebar">
<div class="container">
<div class="top">This is the main sidebar text. It should be in the top left of the sidebar. The sidebar itself should run from the bottom of the header to the bottom of the, and once the user scrolls past the header, the sidebar should take up the full height of
the page.</div>
<div class="bottom">This is some secondary sidebar text. It should always be at the bottom left of the viewport. However, it is partially hidden from view when the page loads because the header pushes it below the viewport.</div>
</div>
</div>
<main>
<h1>
Body text
</h1>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Nihil, id. Sapiente dolores mollitia quo sequi officiis ipsa corrupti minima fugiat rem laudantium natus soluta, ab non porro asperiores nostrum possimus. Lorem ipsum, dolor sit amet consectetur
adipisicing elit. Officia voluptatibus, corporis tempore reiciendis provident delectus temporibus modi in nemo corrupti eum rerum animi, veniam vero? Adipisci voluptas voluptatum similique incidunt. Lorem ipsum dolor sit amet consectetur adipisicing
elit. Minima quasi neque aliquam ea sed quia amet saepe illo placeat? Magnam, possimus a doloribus blanditiis culpa officia ad explicabo dolorem tempora! Lorem ipsum dolor sit amet consectetur adipisicing elit. Rem, velit! Vero eveniet fugit qui dignissimos
incidunt. Debitis repellat pariatur cum totam laboriosam nesciunt, impedit excepturi, eaque veniam commodi odit reiciendis. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aliquid voluptatem ut tempore debitis alias veniam minus natus nemo
id dignissimos dicta nobis rerum dolorem iste, ab blanditiis. Quibusdam, tempore nisi? Lorem ipsum dolor sit amet consectetur adipisicing elit. Est adipisci recusandae architecto explicabo numquam fuga repellat totam eligendi voluptatum, earum ab
doloremque iste assumenda optio. Eveniet ipsa laboriosam rerum dolores. Lorem ipsum dolor, sit amet consectetur adipisicing elit. Tenetur quia velit ratione architecto distinctio nam atque pariatur reprehenderit. Praesentium debitis voluptatum rem
blanditiis, doloremque assumenda quibusdam vero consectetur! Cum, ipsa. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Fugiat rerum tempore voluptatibus! Ut pariatur fugit facilis autem minus eum facere maxime laborum? Cumque dicta magnam,
asperiores nam molestiae laboriosam cupiditate?
</p>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Nihil, id. Sapiente dolores mollitia quo sequi officiis ipsa corrupti minima fugiat rem laudantium natus soluta, ab non porro asperiores nostrum possimus. Lorem ipsum, dolor sit amet consectetur
adipisicing elit. Officia voluptatibus, corporis tempore reiciendis provident delectus temporibus modi in nemo corrupti eum rerum animi, veniam vero? Adipisci voluptas voluptatum similique incidunt. Lorem ipsum dolor sit amet consectetur adipisicing
elit. Minima quasi neque aliquam ea sed quia amet saepe illo placeat? Magnam, possimus a doloribus blanditiis culpa officia ad explicabo dolorem tempora! Lorem ipsum dolor sit amet consectetur adipisicing elit. Rem, velit! Vero eveniet fugit qui dignissimos
incidunt. Debitis repellat pariatur cum totam laboriosam nesciunt, impedit excepturi, eaque veniam commodi odit reiciendis. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aliquid voluptatem ut tempore debitis alias veniam minus natus nemo
id dignissimos dicta nobis rerum dolorem iste, ab blanditiis. Quibusdam, tempore nisi? Lorem ipsum dolor sit amet consectetur adipisicing elit. Est adipisci recusandae architecto explicabo numquam fuga repellat totam eligendi voluptatum, earum ab
doloremque iste assumenda optio. Eveniet ipsa laboriosam rerum dolores. Lorem ipsum dolor, sit amet consectetur adipisicing elit. Tenetur quia velit ratione architecto distinctio nam atque pariatur reprehenderit. Praesentium debitis voluptatum rem
blanditiis, doloremque assumenda quibusdam vero consectetur! Cum, ipsa. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Fugiat rerum tempore voluptatibus! Ut pariatur fugit facilis autem minus eum facere maxime laborum? Cumque dicta magnam,
asperiores nam molestiae laboriosam cupiditate?
</p>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Nihil, id. Sapiente dolores mollitia quo sequi officiis ipsa corrupti minima fugiat rem laudantium natus soluta, ab non porro asperiores nostrum possimus. Lorem ipsum, dolor sit amet consectetur
adipisicing elit. Officia voluptatibus, corporis tempore reiciendis provident delectus temporibus modi in nemo corrupti eum rerum animi, veniam vero? Adipisci voluptas voluptatum similique incidunt. Lorem ipsum dolor sit amet consectetur adipisicing
elit. Minima quasi neque aliquam ea sed quia amet saepe illo placeat? Magnam, possimus a doloribus blanditiis culpa officia ad explicabo dolorem tempora! Lorem ipsum dolor sit amet consectetur adipisicing elit. Rem, velit! Vero eveniet fugit qui dignissimos
incidunt. Debitis repellat pariatur cum totam laboriosam nesciunt, impedit excepturi, eaque veniam commodi odit reiciendis. Lorem ipsum, dolor sit amet consectetur adipisicing elit. Aliquid voluptatem ut tempore debitis alias veniam minus natus nemo
id dignissimos dicta nobis rerum dolorem iste, ab blanditiis. Quibusdam, tempore nisi? Lorem ipsum dolor sit amet consectetur adipisicing elit. Est adipisci recusandae architecto explicabo numquam fuga repellat totam eligendi voluptatum, earum ab
doloremque iste assumenda optio. Eveniet ipsa laboriosam rerum dolores. Lorem ipsum dolor, sit amet consectetur adipisicing elit. Tenetur quia velit ratione architecto distinctio nam atque pariatur reprehenderit. Praesentium debitis voluptatum rem
blanditiis, doloremque assumenda quibusdam vero consectetur! Cum, ipsa. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Fugiat rerum tempore voluptatibus! Ut pariatur fugit facilis autem minus eum facere maxime laborum? Cumque dicta magnam,
asperiores nam molestiae laboriosam cupiditate?
</p>
</main>
Here is how it is cut off
I added this css to the bottom class:
.bottom {
bottom: 0;
position: sticky;
}
No part of this element will be below the viewport.

Child under flexbox is not taking width specified [duplicate]

This question already has answers here:
Flexbox not giving equal width to elements
(5 answers)
Closed 1 year ago.
I have just started learning CSS and I was working on a page using flexbox. The problem is that,
I have a container which is display: flex.
I have a left side image
I have a right side long text.
As you can see in the below snippet, the .content is not taking 50% width.
Any help would be appreciated.
Thanks in advance
.container {
display: flex;
}
img {
max-width: 100%;
}
.content {
width: 50%;
}
<div class='container'>
<img src="https://static.remove.bg/sample-gallery/graphics/bird-thumbnail.jpg" />
<div class='content'>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex asperiores recusandae maxime possimus obcaecati sint atque quas, inventore quo ipsam quam tenetur voluptate excepturi adipisci nihil omnis consequuntur nemo ea?
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex asperiores recusandae maxime possimus obcaecati sint atque quas, inventore quo ipsam quam tenetur voluptate excepturi adipisci nihil omnis consequuntur nemo ea?
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex asperiores recusandae maxime possimus obcaecati sint atque quas, inventore quo ipsam quam tenetur voluptate excepturi adipisci nihil omnis consequuntur nemo ea?</p>
</div>
</div>
You need to specify the flex property as below.
.container {
display: flex;
}
img, .content {
/* max-width: 100%; */
flex: 1;
width: 50%;
}
<div class='container'>
<img src="https://static.remove.bg/sample-gallery/graphics/bird-thumbnail.jpg" />
<div class='content'>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex asperiores recusandae maxime possimus obcaecati sint atque quas, inventore quo ipsam quam tenetur voluptate excepturi adipisci nihil omnis consequuntur nemo ea?
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex asperiores recusandae maxime possimus obcaecati sint atque quas, inventore quo ipsam quam tenetur voluptate excepturi adipisci nihil omnis consequuntur nemo ea?
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ex asperiores recusandae maxime possimus obcaecati sint atque quas, inventore quo ipsam quam tenetur voluptate excepturi adipisci nihil omnis consequuntur nemo ea?</p>
</div>
</div>

Div to always occupy the size of the window in height and width

I'm trying to enter the page to display a div on the entire screen (full width and full height) whatever the size of the browser window. That is to say, that div occupies ALL and until you do not scroll you do not see what is underneath.
It seems to work in the high, because even if you make it higher or smaller the next div below is not seen unless you scroll down, so far so good.
But in the width is another matter, it does not cover me the totality, and on top if I reduce the width of the window of the navigator the text is not molded to that width and the horizontal scroll appears.
Translated with www.DeepL.com/Translator (free version)
HTML code
<div id="slider-total">
<h1>Prueba de titulo</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem nesciunt et explicabo impedit ducimus facere quam ipsum vero, accusamus molestias! Dolore perferendis pariatur esse at eaque qui aspernatur consectetur laboriosam.</p>
</div>
<div id="siguiente">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste blanditiis sint labore, veritatis quidem sed nemo iure velit tenetur aspernatur facere quasi ullam assumenda, recusandae cupiditate laborum dolore excepturi eveniet?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cumque quis iure sunt temporibus nostrum voluptatum doloremque, explicabo deleniti voluptatibus a enim nobis, tenetur perspiciatis repellendus error unde libero vero voluptatem! Lorem ipsum dolor sit amet consectetur adipisicing elit. Illo asperiores ullam ratione iusto error minima temporibus dolores facere, aliquam alias dicta eveniet, debitis quo deserunt soluta, voluptatum optio suscipit expedita. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Delectus enim esse porro mollitia, facilis dolor voluptate iste, facere maxime minus id suscipit. Quaerat dolorum suscipit quo maiores quas temporibus tempore. Lorem ipsum dolor sit amet consectetur adipisicing elit. Quia placeat ullam amet ipsa libero quibusdam inventore fugit dolorum nostrum, animi velit reprehenderit neque, doloribus repudiandae enim vitae ducimus qui harum? Lorem ipsum dolor sit, amet consectetur adipisicing elit. Eaque dolorem sapiente a, ea fuga voluptate mollitia inventore, impedit nihil optio aut itaque consectetur! Corrupti reiciendis quis, odit ducimus quod obcaecati!</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iste blanditiis sint labore, veritatis quidem sed nemo iure velit tenetur aspernatur facere quasi ullam assumenda, recusandae cupiditate laborum dolore excepturi eveniet?</p>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cumque quis iure sunt temporibus nostrum voluptatum doloremque, explicabo deleniti voluptatibus a enim nobis, tenetur perspiciatis repellendus error unde libero vero voluptatem! Lorem ipsum dolor sit amet consectetur adipisicing elit. Illo asperiores ullam ratione iusto error minima temporibus dolores facere, aliquam alias dicta eveniet, debitis quo deserunt soluta, voluptatum optio suscipit expedita. Lorem ipsum dolor sit, amet consectetur adipisicing elit. Delectus enim esse porro mollitia, facilis dolor voluptate iste, facere maxime minus id suscipit. Quaerat dolorum suscipit quo maiores quas temporibus tempore. Lorem ipsum dolor sit amet consectetur adipisicing elit. Quia placeat ullam amet ipsa libero quibusdam inventore fugit dolorum nostrum, animi velit reprehenderit neque, doloribus repudiandae enim vitae ducimus qui harum? Lorem ipsum dolor sit, amet consectetur adipisicing elit. Eaque dolorem sapiente a, ea fuga voluptate mollitia inventore, impedit nihil optio aut itaque consectetur! Corrupti reiciendis quis, odit ducimus quod obcaecati!</p>
</div>
CSS code:
* {
box-sizing: border-box;
}
#slider-total {
width: 100vh;
height: 100vh;
background-color: #444;
color: white;
display: flex;
flex-flow: column wrap;
align-items: center;
justify-content: center;
}
What am I doing wrong?
Thanks
Your width is 100vh, or 100 percentiles of the viewport height. It makes sense, therefore, that the width of the <div> will be smaller than needed if you have a viewport that is wider than it is tall. It should be 100vw, or 100 percentiles of the viewport width.

How to keep bootstrap columns of same size so that they snap correctly?

I'm building a simple site with bootstrap columns, but I would like for them to stay with the same height, since as of right now, if the last column in the row is short in height, the next one gets placed below it instead of on the next row to the left. How could I do this?
.col-xs-3 {
border: 1px solid red;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="row ">
<div class="col-xs-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut nisi, quia. Nobis, quam, provident. Quam quidem reiciendis, aliquid fugiat assumenda deserunt officiis, animi ad magnam explicabo officia dolorem perspiciatis et?</div>
<div class="col-xs-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque quibusdam, odit consequuntur, eligendi, laborum dolores modi, dignissimos praesentium cumque aut obcaecati at. Quaerat ducimus, nam, sint perspiciatis tenetur distinctio nobis.</div>
<div class="col-xs-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos labore, delectus dignissimos, laudantium, similique tempore cumque voluptatum placeat eos minima modi, veritatis! Cumque, asperiores eveniet animi architecto adipisci voluptatum sed?</div>
<div class="col-xs-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero dolorum pariatur optio!</div>
<div class="col-xs-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero dolorum pariatur optio vel molestiae quo commodi quidem, nostrum porro dicta explicabo assumenda, beatae. Autem voluptatem laudantium facilis, iste at, nesciunt!</div>
</div>
</div>
edit: since the snippet isn't showing correctly to show my issue, here is a codepen: http://codepen.io/sgarcia-dev/pen/zqbjBg
edit2: I saw the other threads, but those show how to set them to the same height without needing columns to be responsive. I can't use flexbox for IE reasons, and I need to keep the HTML clean enough so that these columns have more than one column size (col-md-3, col-xs-6, etc). My current solution which for some reason doesn't work is doing this:
.col-sm-3:nth-child(3n):after {
content: "";
display: table;
clear: both;
}
Can someone help?
Placing <div class="clearfix"></div> should fix the issue
<div class="container">
<div class="row ">
<div class="col-sm-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut nisi, quia. Nobis, quam, provident. Quam quidem reiciendis, aliquid fugiat assumenda deserunt officiis, animi ad magnam explicabo officia dolorem perspiciatis et?</div>
<div class="col-sm-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque quibusdam, odit consequuntur, eligendi, laborum dolores modi, dignissimos praesentium cumque aut obcaecati at. Quaerat ducimus, nam, sint perspiciatis tenetur distinctio nobis.</div>
<div class="col-sm-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos labore, delectus dignissimos, laudantium, similique tempore cumque voluptatum placeat eos minima modi, veritatis! Cumque, asperiores eveniet animi architecto adipisci voluptatum sed?</div>
<div class="col-sm-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero dolorum pariatur optio vel molestiae quo commodi quidem</div>
<div class="clearfix"></div>
<div class="col-sm-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero dolorum pariatur optio vel molestiae quo commodi quidem, nostrum porro dicta explicabo assumenda, beatae. Autem voluptatem laudantium facilis, iste at, nesciunt!</div>
</div>
</div>
From the question and your comments on previous replies, it sounds as if you do not actually want/need equal sizes columns (which would include stuff such as backgrounds, borders extending to the same height for all, which would be rather easy to achieve with flexbox - maybe as nice-to-have in supporting browsers), at least not as the main goal; but you rather just want the "boxes" that flow onto a second (, third, ...) "row" or rather line to all have the y-position of their top edge match that of the bottom edge of the highest column in the previous row.
That is quite easy to achieve, if you forgo bootstrap's floating, and use display:inline-block on the columns instead.
Then of course you will have to eliminate the space between the columns that inline-block brings with it - but that is a well known issue with several possible fixes, see https://css-tricks.com/fighting-the-space-between-inline-block-elements/ - I chose the font-size 0 on the parent element here, but if you need to satisfy older IE you might need to use an absolute font-size for the "re-set" on the columns rather than the rem I used in the example.
.row {
font-size: 0; /* fight white space */
}
.col-md-3,
.col-sm-6 { /* add selectors for more of the col-variants if needed */
border: 1px solid red;
float: none; /* disable floating */
display: inline-block; /* make inline-block instead */
vertical-align: top; /* have top edges of elements on one line align */
font-size: 1.5rem; /* reset font-size */
}
http://codepen.io/anon/pen/ezJQLM
IMHO this solution has a nice benefit/advantage in that you don't need to alter anything regarding bootstrap's column width definitions or wrestle floats into shape using adventurously placed clearfixes.
The reason that you have 1 col getting pushed below the other is becuase you are using the class: col-xs-3 with 5 col's. Bootstrap works off the fact that you can only have an additive total of 12 per "row" on the same "row"
3 * 5 = 15, so you get 1 pushed down to it's own "row, allowing 4 to be on the same row; 3 * 4 = 12.
If you instead use the col-xs-2 class, you will have all on the same "row"; 2 * 5 = 10
Do the following to correct your problem:
.col-xs-2 {
border: 1px solid red;
}
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="row ">
<div class="col-xs-2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut nisi, quia. Nobis, quam, provident. Quam quidem reiciendis, aliquid fugiat assumenda deserunt officiis, animi ad magnam explicabo officia dolorem perspiciatis et?</div>
<div class="col-xs-2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque quibusdam, odit consequuntur, eligendi, laborum dolores modi, dignissimos praesentium cumque aut obcaecati at. Quaerat ducimus, nam, sint perspiciatis tenetur distinctio nobis.</div>
<div class="col-xs-2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos labore, delectus dignissimos, laudantium, similique tempore cumque voluptatum placeat eos minima modi, veritatis! Cumque, asperiores eveniet animi architecto adipisci voluptatum sed?</div>
<div class="col-xs-2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero dolorum pariatur optio!</div>
<div class="col-xs-2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero dolorum pariatur optio vel molestiae quo commodi quidem, nostrum porro dicta explicabo assumenda, beatae. Autem voluptatem laudantium facilis, iste at, nesciunt!</div>
</div>
</div>
EDIT PER COMMENTS:
To push the other column to it's own row, place it in another div that has the row class.
<div class="container">
<div class="row ">
<div class="col-sm-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aut nisi, quia. Nobis, quam, provident. Quam quidem reiciendis, aliquid fugiat assumenda deserunt officiis, animi ad magnam explicabo officia dolorem perspiciatis et?</div>
<div class="col-sm-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Atque quibusdam, odit consequuntur, eligendi, laborum dolores modi, dignissimos praesentium cumque aut obcaecati at. Quaerat ducimus, nam, sint perspiciatis tenetur distinctio nobis.</div>
<div class="col-sm-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quos labore, delectus dignissimos, laudantium, similique tempore cumque voluptatum placeat eos minima modi, veritatis! Cumque, asperiores eveniet animi architecto adipisci voluptatum sed?</div>
<div class="col-sm-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero dolorum pariatur optio vel molestiae quo commodi quidem</div>
</div>
<div class="row">
<div class="col-sm-3">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Libero dolorum pariatur optio vel molestiae quo commodi quidem, nostrum porro dicta explicabo assumenda, beatae. Autem voluptatem laudantium facilis, iste at, nesciunt!</div>
</div>
</div>
.col-sm-3 {
border: 1px solid red;
}

Collapse divs vertically CSS

I'm working on a website and I've this code
.container {
width: 100%;
margin:0 auto;
}
.container div {
width: 25%;
display: inline-block;
vertical-align:top;
background: lightblue;
border: 1px solid black
}
<div class="container">
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Explicabo nisi, sit eius provident, vitae, quisquam impedit dolore ad aperiam incidunt optio consequuntur aliquam facilis hic ullam! Quisquam tempora, fuga numquam.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis quod, ipsa quidem natus quis quam odit molestiae sit, debitis amet expedita fugiat nesciunt at modi eos, porro laborum quas optio.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Facilis, necessitatibus alias atque nulla praesentium dolorem, dignissimos autem culpa placeat quae doloribus unde illo fugiat! Delectus quia recusandae aperiam est eligendi quae doloribus unde illo fugiat! Delectus quia recusandae aperiam est eligendi.</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempora labore optio placeat aperiam facilis recusandae velit, minus modi quo dolores molestias in ratione officia accusantium, reiciendis porro, ipsam, repellendus atque!</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maxime quisquam ratione ducimus temporibus rerum, voluptatum facilis repellat quos nostrum commodi adipisci hic libero, rem optio consequatur tempora sed sequi voluptas!</p>
</div>
<div>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio dolor nobis veritatis deserunt voluptate illum, voluptatibus consequuntur optio autem sint, accusamus ipsam, quidem nesciunt doloribus similique doloremque magni dolorem. Animi.</p>
</div>
</div>
I want my divs collapse vertically like this image :
I try to add a float: left; but it does not work.
Thanks for your help !
Add flex properties to your .container class.
.container {
width: 100%;
margin:0 auto;
display:flex;
flex-wrap:wrap;
}
It is not that easy to achieve with few lines of html + css when you don't want to use flexbox.
I suspect you should give a try this plugin:
http://masonry.desandro.com/