Bootstrap 3 nesting columns, nested row height - css

Why nested .row takes height of parent .row?
Example:
<div class="container">
<div class="row"> <!-- Parent .row -->
<div class="col-md-8">
<div class="col-md-6"></div>
<div class="col-md-3"></div>
<div class="col-md-3"></div>
<div class="row"> <!-- nested PROBLEMATIC ROW -->
<div class="col-md-12">
Why this row has height of 300px instead of 150px?
I can solve problem by setting 'clear: both' on that
row, but class .row should do it by itself.
</div>
</div>
</div>
<div class="col-md-4">
<div></div>
<div></div>
<div></div>
</div>
</div>
</div>
With some dummy css:
.col-md-8 {
height: 500px;
background: #f0f0f0;
}
.col-md-6 {
height: 150px;
background: red;
}
.col-md-3 {
height: 150px;
background: blue;
}
.col-md-12 {
height: 150px;
background: yellow;
}
.col-md-4 {
height: 500px;
background #f0f0f0;
}
.col-md-4 > div {
margin-bottom: 10px;
height: 150px;
background: green;
}
Final output:
JS Bin : http://jsbin.com/nugoziju/1/edit

To begin with, you shouldn't be putting 'col's inside 'col's in Bootstrap without the corresponding row. So your markup looks like this:
<div class="container">
<div class="row"> <!-- Parent .row -->
<div class="col-md-8">
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-3"></div>
<div class="col-md-3"></div>
</div>
<div class="row"> <!-- nested PROBLEMATIC ROW -->
<div class="col-md-12">
Why this row has height of 300px instead of 150px?
I can solve problem by setting 'clear: both' on that
row, but class .row should do it by itself.
</div>
</div>
</div>
<div class="col-md-4">
<div></div>
<div></div>
<div></div>
</div>
</div>
And then that's fixed. That row is 150px tall.
Updated jsbin: http://jsbin.com/nugoziju/7

Related

How to get three div in one line

I would like to align three div in one line with a little space between first div and second div and last div using bootstrap as you see in the picture :
I try with this code :
<div class="row">
<div class="col-md-2">
<img src="img/emo_positif.png')}}">
</div>
<div class="col-md-7">
<div class="square1"></div>
</div>
<div class="col-md-3">
<img src="img/emo_negative.png')}}">
</div>
</div>
but it shows me a big space between the div
Using Bootstrap 3:
.row {
height: 24px;
}
.row > div {
height: 100%;
}
.square {
background: pink;
}
.square1 {
background: #01a8ff;
height: 100%;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" >
<div class="row">
<div class="col-xs-2 square">
</div>
<div class="col-xs-8">
<div class="square1"></div>
</div>
<div class="col-xs-2 square">
</div>
</div>
Check this Pen.
Read the docs.
For making the three division in same line . There are many ways. For better UX use display:flex in css for the parent division
Thanks

How to span rows in Bootstrap?

I'm trying to achieve a layout like below in Bootstrap but am having a difficult time with it. I feel dumb asking this but it's my first time using Bootstrap and I couldn't find a similar example on here.
Thanks!
I thought maybe something like this, but div C clears div B and ends up way too far down the page.
<div class="container">
<div class="row">
<div class="col-md-8">
A
</div>
<div class="col-md-4">
B
</div>
</div>
<div class="row">
<div class="col-md-8">
C
</div>
</div>
</div>
If you need a pure bootstrap solution you need to add col-xs-12 to make it 100% on mobiles and col-sm-6 to make it 50% on desktop. The add pull-left and pull-right to avoid the B panel to clear and move C below everything
.bg-danger, .bg-primary {
height: 200px;
}
.bg-success {
height: 400px;
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<div class="row container-fluid">
<div class="col-sm-6 col-xs-12 bg-danger pull-left"></div>
<div class="col-sm-6 col-xs-12 bg-success pull-right"></div>
<div class="col-sm-6 col-xs-12 bg-primary pull-left"></div>
</div>
</div></body>
</html>
Click full page to see the difference
Here we have an explanation about the grid system.
http://getbootstrap.com/css/#grid
Here's a simple solution:
<div class="container">
<div class="row">
<div class="col-sm-6">
<div class="row">
<div class="col-sm-12">
</div>
<div class="col-sm-12">
</div>
</div>
</div>
<div class="col-sm-6">
</div>
</div>
</div>
The page is split in half with the two outer columns "col-sm-6", with one of these columns containing two inner columns that span it's entire width
A simple solution if you want essentailly the green box to come in between.
Check this Bootply for responsive-ness check.
Snippet here:
.something {
height: 100px;
margin-top: 10px;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="something bg-danger"></div>
</div>
<div class="col-md-6">
<div class="something bg-success"></div>
</div>
<div class="col-md-6">
<div class="something bg-primary"></div>
</div>
</div>
</div>
Here is another example where the Green box will come below the rest two boxes..:
.something {
height: 100px;
margin-top: 10px;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div clas="col-md-6">
<div class="col-md-12">
<div class="something bg-danger"></div>
</div>
<div class="col-md-12">
<div class="something bg-primary"></div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="something bg-success"></div>
</div>
</div>
</div>
You should use Pure CSS Flexbox for this.
Have a look at the snippet below (use full screen for desktop mode):
.box-holder {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
flex-wrap: wrap;
width: 300px;
height: 280px;
}
.box {
display: flex;
justify-content: center;
align-items: center;
width: 100px;
height: 100px;
border: 1px solid #000;
color: #fff;
margin: 15px;
font-size: 40px;
font-weight: 200;
}
.a {
background: red;
}
.b {
align-self: flex-start;
order: 1;
background: green;
height: 240px;
margin: 0;
}
.c {
background: blue;
}
/* On Mobiles */
#media screen and (max-width: 700px) {
.box-holder {
width: auto;
height: auto;
}
.b {
align-self: center !important;
order: 0;
margin: 15px;
}
}
<div class="box-holder">
<div class="box a">A</div>
<div class="box b">B</div>
<div class="box c">C</div>
</div>
Hope this helps!
I hope this helps..:)
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-sm-3"><!--div for the left side abc pattern starts-->
<div class="row">
<div class="col-sm-12">
"standing a"
</div>
</div>
<div class="row">
<div class="col-sm-12">
"standing b - adjust the height of this block"
</div>
</div>
<div class="row">
<div class="col-sm-12">
"standing c"
</div>
</div>
</div><!-- div for the left side abc pattern ends -->
<div class="col-sm-6"><!-- div for the right side abc pattern starts -->
<div class="row">
<div class="col-sm-6">
<div class="row">
<div class="col-sm-12">
"block a"
</div>
</div>
<div class="row">
<div class="col-sm-12">
"block b"
</div>
</div>
</div>
<div class="col-sm-6">
"block c"
</div>
</div>
</div><!-- div for the right side abc pattern ends -->
</div><!-- row closed here -->
</div>

Bootstrap complex column position ordering

Is it possible to pull/push divs of a column from another column in Bootstrap grid system? For example:
At desktop view: it's like this way:
Parent Column 1 | Parent Column 2
First Content | Second Content
Third Content | Fourth Content
At mobile view, it's like this way:
Parent Column 1
First Content
Second Content
Parent Column 2
Third Content
Fourth Content
Please take a look on this fiddle to understand what I am trying to mean.Thanks in advance.
You can achieve it by using bootstrap's grid.
.first {
background: yellow;
height: 300px;
}
.second {
background: red;
height: 100px;
color: white;
}
.third {
background: green;
height: 300px;
color: white;
}
.fourth {
background: blue;
height: 100px;
color: white;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 col-xs-12 first">
FIRST
</div>
<div class="col-sm-6 col-xs-12 second">
SECOND
</div>
<div class="col-sm-6 col-xs-12 third">
THIRD
</div>
<div class="col-sm-6 col-xs-12 fourth">
FOURTH
</div>
</div>
</div>
Or you can use Masonry JS:
var $container = $('.masonry-container');
$container.masonry({
columnWidth: '.item',
itemSelector: '.item'
});
.first {
background: yellow;
height: 300px;
}
.second {
background: red;
height: 100px;
color: white;
}
.third {
background: green;
height: 300px;
color: white;
}
.fourth {
background: blue;
height: 100px;
color: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/masonry/4.1.1/masonry.pkgd.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="row masonry-container">
<div class="col-sm-6 col-xs-12 first item">
FIRST
</div>
<div class="col-sm-6 col-xs-12 second item">
SECOND
</div>
<div class="col-sm-6 col-xs-12 third item">
THIRD
</div>
<div class="col-sm-6 col-xs-12 fourth item">
FOURTH
</div>
</div>
</div>
I think the issue is more of a float problem because your columns have variable height. Create a special class to pull the 2nd and 3rd columnd right on larger screens..
#media (min-width: 992px) {
.pull-md-right {
float:right;
}
}
And, use it like this..
<div class="row">
<div class="col-md-6">
<div class="first">First</div>
</div>
<div class="col-md-6 pull-md-right">
<div class="second">Second</div>
</div>
<div class="col-md-6 pull-md-right">
<div class="third">Third</div>
</div>
<div class="col-md-6">
<div class="fourth">Fourth</div>
</div>
</div>
http://codeply.com/go/CYteNdheKS
In Bootstrap 4, responsive floats are included so you won't need the extra CSS.

Center Div scroll

In my code,
Within one container Three blocks will be there. one freezes on the left and one freezes on the right and the other will scroll in between these two divs. Just like modern grids. But I don't want to use the grid.
I have tried, but the center block is not getting the Horizontal scroll.
I want no breakage of the center block, instead, it should scroll horizontally.
* {
box-sizing: border-box;
}
.container {
width: 100%;
overflow: auto;
white-space: nowrap
}
.scroll-center {
width: auto;
overflow: auto;
display: block;
white-space: nowrap
}
.row {
float: left;
}
.cell {
padding: 3px;
border: 1px solid #bbb;
min-height: 25px;
min-width: 200px;
}
<div class="container">
<div class="row">
<div class="cell">HeaderL1</div>
<div class="cell">HeaderL2</div>
<div class="cell">HeaderL3</div>
</div>
<div class="scroll-center">
<div class="row">
<div class="cell">HeaderT2</div>
<div class="cell">Data21</div>
<div class="cell">Data22</div>
</div>
<div class="row">
<div class="cell">HeaderT3</div>
<div class="cell">Data31</div>
<div class="cell">Data32</div>
</div>
<div class="row">
<div class="cell">HeaderT4</div>
<div class="cell">Data41</div>
<div class="cell">Data42</div>
</div>
<div class="row">
<div class="cell">HeaderT5</div>
<div class="cell">Data51</div>
<div class="cell">Data52</div>
</div>
<div class="row">
<div class="cell">HeaderT6</div>
<div class="cell">Data61</div>
<div class="cell">Data62</div>
</div>
<div class="row">
<div class="cell">HeaderT7</div>
<div class="cell">Data71</div>
<div class="cell">Data72</div>
</div>
<div class="row">
<div class="cell">HeaderT8</div>
<div class="cell">Data81</div>
<div class="cell">Data82</div>
</div>
<div class="row">
<div class="cell">HeaderT9</div>
<div class="cell">Data91</div>
<div class="cell">Data92</div>
</div>
</div>
<div class="right">
<div class="row">
<div class="cell">HeaderTR</div>
<div class="cell">DataR1</div>
<div class="cell">DataR2</div>
</div>
</div>
</div>
You probably need to add width to your container. Right now it's set to 100% so it will not size beyond the browser window. Instead you could do something like this:
.container {
overflow: auto;
white-space: nowrap;
width:2000px;
}
I realize that you may need to change this value dynamically but hopefully this gets you started
Example:http://codepen.io/nilestanner/pen/jAjbdK
Try with For example:
css:
* {
box-sizing: border-box;
}
.left, .center, .right{
float:left
}
.center {
width:400px;
overflow: scroll;
display: block;
white-space: nowrap
}
#center-scroll{
width:2000px;
}
.center .row{
display:inline-block;
width:33%;
}
.center .row .cell{
min-width:100%;
}
.row{
float:left;
}
.cell {
padding: 3px;
border: 1px solid #bbb;
min-height: 25px;
min-width: 200px;
}
HTML
<div class="container">
<div class="left">
<div class="row" >
<div class="cell">HeaderL1</div>
<div class="cell">HeaderL2</div>
<div class="cell">HeaderL3</div>
</div>
</div>
<div class="center">
<div id="center-scroll">
<div class="row">
<div class="cell">HeaderT2</div>
<div class="cell">Data21</div>
<div class="cell">Data22</div>
</div>
<div class="row">
<div class="cell">HeaderT3</div>
<div class="cell">Data31</div>
<div class="cell">Data32</div>
</div>
<div class="row">
<div class="cell">HeaderT4</div>
<div class="cell">Data41</div>
<div class="cell">Data42</div>
</div>
<div class="row">
<div class="cell">HeaderT5</div>
<div class="cell">Data51</div>
<div class="cell">Data52</div>
</div>
<div class="row">
<div class="cell">HeaderT6</div>
<div class="cell">Data61</div>
<div class="cell">Data62</div>
</div>
<div class="row">
<div class="cell">HeaderT7</div>
<div class="cell">Data71</div>
<div class="cell">Data72</div>
</div>
<div class="row">
<div class="cell">HeaderT8</div>
<div class="cell">Data81</div>
<div class="cell">Data82</div>
</div>
<div class="row">
<div class="cell">HeaderT9</div>
<div class="cell">Data91</div>
<div class="cell">Data92</div>
</div>
</div>
</div>
<div class="right">
<div class="row">
<div class="cell">HeaderTR</div>
<div class="cell">DataR1</div>
<div class="cell">DataR2</div>
</div>
</div>
</div>

bootstrap 3 row-same-height does not work

In this sample all the columns share the same height:
http://www.minimit.com/demos/bootstrap-3-responsive-columns-of-same-height
In my sample: http://codepen.io/helloworld/pen/ogrjML
The same css code does not produce the same output of same height columns.
What do I wrong?
I can not use Flexbox!
<div class="container">
<div class="row">
<div class="row-same-height row-full-height">
<div style="background:orange;" class="col-xs-9 col-xs-height col-full-height">
<div class="item">
<div class="content">
<br><br><br><br><br><br><br>
</div>
</div>
</div>
<div style="background:red;" class="col-xs-3 col-xs-height col-full-height">
<div class="item"><div class="content">test2</div></div>
</div>
</div>
</div>
</div>
There are some styles in the minimit example that are not included in bootstrap. You need to add the following to get the heights you desire:
.row-same-height {
display: table;
width: 100%;
}
.col-xs-height {
display: table-cell;
float: none;
}
.col-full-height {
height: 100%;
vertical-align: middle;
}
Demo

Resources