Bootstrap 3 grid - pull columns to the top as much as possible - css

I have a <row> with 6 columns, height of each column is unknown. On small screen it should turn into 2 rows with 3 columns.
This is how it looks on md screen:
This is how it looks on sm screen:
I'm using the clearfix trick described in the docs
Question: how do I keep it in 2 rows of 3 columns but pull the columns to the top as much as possible? a4 should touch c1 and a5 should touch d2.
Full code:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row" style="color:black;font-size: 1.5em;">
<div class="col-md-2 col-sm-4">
<div style="background-color: blue;">a0</div>
<div style="background-color: white;">b0</div>
<div style="background-color: white;">c0</div>
<div style="background-color: white;">d0</div>
<div style="background-color: white;">e0</div>
</div>
<div class="col-md-2 col-sm-4">
<div style="background-color: blue;">a1</div>
<div style="background-color: white;">b1</div>
<div style="background-color: white;">c1</div>
</div>
<div class="col-md-2 col-sm-4">
<div style="background-color: blue;">a2</div>
<div style="background-color: white;">b2</div>
<div style="background-color: white;">c2</div>
<div style="background-color: white;">d2</div>
</div>
<div class="clearfix visible-sm-block"></div>
<div class="col-md-2 col-sm-4">
<div style="background-color: blue;">a3</div>
<div style="background-color: white;">b3</div>
<div style="background-color: white;">c3</div>
<div style="background-color: white;">d3</div>
<div style="background-color: white;">e3</div>
</div>
<div class="col-md-2 col-sm-4">
<div style="background-color: blue;">a4</div>
<div style="background-color: white;">b4</div>
<div style="background-color: white;">c4</div>
<div style="background-color: white;">d4</div>
</div>
<div class="col-md-2 col-sm-4">
<div style="background-color: blue;">a5</div>
<div style="background-color: white;">b5</div>
<div style="background-color: white;">c5</div>
<div style="background-color: white;">d5</div>
</div>
</div>

Normally you'd need JS for this—something like Isotope or Masonry. You can do it with CSS3, but older browsers won't support it:
Instead of floating the boxes, just add this to the container:
.row {
-moz-column-count: 3;
-webkit-column-count: 3;
column-count: 3;
}

Related

why is col-xs-* no effect when zomming out browser?

This is html:
<div class="container-fluid">
<h1>Hello, world!</h1>
<div class="row">
<div class="col-xs-6 col-sm-3" style="background-color: red;">
<p>lskdflsjdlfsjdlf sdljsdsdfs dfsdfsdfsf</p>
</div>
<div class="col-xs-6 col-sm-3" style="background-color: green;">
<p>lskdflsjdlfsjdlfsdljsdsdfsd sdfsdfsf</p>
</div>
<div class="col-xs-6 col-sm-3" style="background-color: blue;">
<p>lsdflksjdfsldkfjlsd jflskjd</p>
</div>
<div class="col-xs-6 col-sm-3" style="background-color: yellow;">
<p>lsdjflksjdfkmsld mflsd mlksdf</p>
</div>
</div>
</div>
effect picture when zooming out browser:
This is sample part,but I don't know what is happened?
I know the reason. My bootstrap version is 4.0.0 and its extra small is .col- rather than .col-xs-.

How to strech the grid items in a Cartesian plane made with Bootstrap4 and Flex?

I need to implement a cartesian plane with Bootstrap 4 and Flex. The desired output is something like the following image:
The plane is composed by a 10x10 matrix. Moreover I need a row containing the x labels and a column showing the y labels.
Here you are my code:
<div class="d-flex p-2" style="border: 1px solid black; width: 40%; margin-bottom: 50px;">
<div class="d-flex flex-row">
<div class="p-2 align-items-stretch">1</div>
</div>
<div class="d-flex flex-column">
<div class="p-2">1</div>
<div class="p-2">2</div>
<div class="p-2">3</div>
<div class="p-2">4</div>
<div class="p-2">5</div>
<div class="p-2">6</div>
<div class="p-2">7</div>
<div class="p-2">8</div>
<div class="p-2">9</div>
<div class="p-2">10</div>
<div class="p-2 align-items-stretch">11</div>
</div>
<div class="d-flex flex-column">
<div class="p-2">1</div>
<div class="p-2">2</div>
<div class="p-2">3</div>
<div class="p-2">4</div>
<div class="p-2">5</div>
<div class="p-2">6</div>
<div class="p-2">7</div>
<div class="p-2">8</div>
<div class="p-2">9</div>
<div class="p-2">10</div>
</div>
<!-- the same for the other 8 rows -->
</div>
And the associated css:
.p-2 {
border: 1px solid lightgray;
}
.p-2:before {
content:'';
float:left;
padding-top:100%;
}
The actual result is:
I have two problems:
the row number 11 should be stretched until the last column;
the grid items should adapt their size according to the available space
of the container.
How I can reach these goals? Thank you
You can use the Bootstrap grid like this...
Demo: https://www.codeply.com/go/sQA6tvHiZh
<div class="container text-center">
<div class="row">
<div class="col-md-8 mx-auto">
<div class="row">
<div class="col-1">y</div>
<div class="col-11">
<div class="row">
<div class="col">1
</div>
<div class="col">2
</div>
<div class="col">3
</div>
<div class="col">4
</div>
<div class="col">5
</div>
<div class="col">6
</div>
<div class="col">7
</div>
<div class="col">8
</div>
<div class="col">9
</div>
<div class="col">10
</div>
</div>
<!--/row-->
9 more row ...
<div class="row">
<div class="col">x
</div>
</div>
</div>
</div>
</div>
</div>
<!--container-->
</div>

Bootstrap offstet only on md doesn't work

Hello im trying to add offset only on medium device and hide this offset on others devices. I I looked through some others similar questions but any of them could solved my problem.
Here's code:
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3" style="background-color: red"> 111 </div>
<div class="col-lg-4 col-md-4 col-sm-5 col-sm-offset-1" style="background-color: blue"> 222 </div>
<div class="col-lg-3 col-md-4 col-sm-1" style="background-color: black"> 333 </div>
<div class="col-lg-2 col-md-1 col-sm-2" style="background-color: orange"> 444 </div>
</div>
</div>
So the problem is that it add offset on every device not only on medium how it should be.
Screen on large: https://zapodaj.net/f4b34ebc771fb.png.html
I think offset needs to be "reset" on larger screens, otherwise it inherits the previous value. Using col-sm-offset-1 col-md-offset-0 seems to fix the issue.
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3" style="background-color: red"> 111 </div>
<div class="col-lg-4 col-md-4 col-sm-5 col-sm-offset-1 col-md-offset-0" style="background-color: blue"> 222 </div>
<div class="col-lg-3 col-md-4 col-sm-1" style="background-color: black"> 333 </div>
<div class="col-lg-2 col-md-1 col-sm-2" style="background-color: orange"> 444 </div>
</div>
</div>
If you want your offset on medium devices use col-md-offset-1 and not col-sm-offset-1.
You also need to reset the offset for large devices with col-lg-offset-0.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3" style="background-color: red">111</div>
<div class="col-lg-4 col-md-4 col-sm-5 col-md-offset-1 col-lg-offset-0" style="background-color: blue">222</div>
<div class="col-lg-3 col-md-4 col-sm-1" style="background-color: black">333</div>
<div class="col-lg-2 col-md-1 col-sm-2" style="background-color: orange">444</div>
</div>
</div>

Bootstrap 3 two responsive rows next to each other?

I'm using Bootstrap 3 and trying to solve this what's mocked on the image. I used one row with two cols, and they are next to each other like in the image, but when I resize to mobile I want the right side to fall beneath the left. Any help is appreciated, thank you.
Code sample:
<div className="container">
<div className="row">
<div className="col-xs-4 col-offset-xs-1">
<h1>1</h1>
</div>
<div className="col-xs-4">
<div className="row">
<h1>2</h1>
</div>
</div>
.black{background-color:#000; height:320px;}
.red{background-color:#F00; height:100px;margin-bottom:10px;}
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="container">
<div class="row">
<div class="col-xs-6">
<div class="row">
<div class="col-xs-12 black">
black
</div>
</div>
</div>
<div class="col-xs-6">
<div class="row">
<div class="col-xs-12 red">
one
</div>
</div>
<div class="row">
<div class="col-xs-12 red">
two
</div>
</div>
<div class="row">
<div class="col-xs-12 red">
three
</div>
</div>
</div>
</div>
</div>
Bootstrap allows nesting your elements easily, here you go: https://jsfiddle.net/denea/DTcHh/25594/
<div className="container">
<div class="row">
<div class="col-sm-6 col-xs-12" id="first">
<h1>1</h1>
</div>
<div class="col-sm-6 col-xs-12" id="second">
<div class="row">
<h1>2</h1>
</div>
<div class="row">
<h1>3</h1>
</div>
<div class="row">
<h1>4</h1>
</div>
</div>
</div>
and read this: http://getbootstrap.com/css/#grid-nesting
Bootstrap allows for nesting which will provide what you need:
<div class="row">
<div class="col-sm-6">
Left column
</div>
<div class="col-sm-6">
<div class="row">
<div class="col-sm-12">
Right column, row 1
</div>
</div>
<div class="row">
<div class="col-sm-12">
Right column, row 2
</div>
</div>
<div class="row">
<div class="col-sm-12">
Right column, row 3
</div>
</div>
</div>
</div>
More info here.
You can achieve this by using flexbox and media query
#media (max-width: 360px) {
.container > .row {
display:flex;
flex-flow: row-reverse wrap;
}
}
Demo: https://jsfiddle.net/xs3joev8/1/

Bootstrap multi row elements

I am working on a design for a website and practicing bootstrap in the meantime, so I am rather new to it. Now, I understand the grid division into 12 columns and then layering of elements into multiple rows and separating by column span. The question I have is how can I handle elements that span multiple rows next to the elements that span less.
Desired Layout Example
Now, on this example image, how would I accomplish the stacking of the 3 x 4 and the 3x2 and 3x3 blocks? Also, the elements shouldn't be resized vertically.
Since I am relatively new to Bootstrap and responsive design in general, I am open for other frameworks and/or workarounds.
Something like this needs quite a lot of nested containers to get your desired effect but it is all possible.
The heights of some of the elements is a little bit off but once content is filled out, it should look fine.
Below is a working example
div {
border: 1px solid #000;
box-sizing: border-box;
}
div div {
border: 1px solid #444;
}
div div div {
border: 1px solid #888;
}
div div div div {
border: 1px solid #bbb;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
<div class="col-xs-1">1x1</div>
</div>
<div class="row">
<div class="col-xs-3">
<div class="row">
3x2
</div>
<div class="row">
3x3
</div>
</div>
<div class="col-xs-9">
<div class="row">
<div class="col-xs-4">
3x4
</div>
<div class="col-xs-8">
<div class="row">
<div class="col-xs-6">
3x2
</div>
<div class="col-xs-6">
3x2
</div>
<div class="col-xs-12">
6
</div>
<div class="col-xs-12">
6
</div>
</div>
</div>
<div class="col-xs-12">
<div class="row">
<div class="col-xs-4">
<div class="row">
<div class="col-xs-4">
1
</div>
<div class="col-xs-4">
1
</div>
<div class="col-xs-4">
1
</div>
</div>
</div>
<div class="col-xs-8">
<div class="row">
<div class="col-xs-2">
1
</div>
<div class="col-xs-2">
1
</div>
<div class="col-xs-2">
1
</div>
<div class="col-xs-2">
1
</div>
<div class="col-xs-2">
1
</div>
<div class="col-xs-2">
1
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Something like below. It is not complete HTML, but it can give you an idea as to how you can use the horizontal and vertical bootstrap grids (basically through nesting):
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<div class='container'>
<div class='row'>
<div class='form-horizontal'>
<!--First Row-->
<div class='form-group'>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
<div class='col-md-1'></div>
</div>
<!--Second Row-->
<div class='form-group'>
<div class='col-md-3'>
<div class='form-group'></div>
<div class='form-group'></div>
</div>
<div class='col-md-3'>
<div class='form-group'></div>
<div class='form-group'></div>
<div class='form-group'></div>
<div class='form-group'></div>
</div>
<div class='col-md-6'>
<div class='form-group'>
<div class='col-md-6'>
<div class='form-group'></div>
<div class='form-group'></div>
</div>
<div class='col-md-6'>
<div class='form-group'></div>
<div class='form-group'></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Resources