Bootstrap rows & col responsive - css

Using bootstrap's grid, is it possible to build something responsive like this?
This is what I attempted at so far.
<div class="row">
<div class="panel panel-default profile_header">
<div class="panel-body">
<% for user in #users %>
<div class="col-xs-5 col-md-3">
<%= image_tag(user.avatar.url(:medium), :class => "avatar_profile") %>
</div>
<div class="col-xs-7 col-md-9">
<h2 class="profile_name"><%= user.name %></h2>
<div class="row">
<div class="col-xs-12 col-md-12">
<h2 class="profile_bio"><%= user.bio%></h2>
</div>
</div>
</div>
<% end %>
</div>
</div>
</div>
But for mobile, I want the purple column to pop out and displayed under. The content is too crunched up right now, and breaking it into its own full width box would be much better. Is it possible though?

You didn't ask how cells should look for sm viewport (from 768px till 991px) It should look like for md or like for xs?
Here is a snippet for md and xs viewports
.purple {
background: purple;
}
.orange {
background: orange;
}
.green{
background: green;
}
div[class^="col-"]{
height: 100px;
}
#media screen and (min-width: 992px) {
div.orange {
height: 200px !important;
}
}
<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-md-3 col-xs-5 orange">
</div>
<div class="col-md-9 col-xs-7 green">
</div>
<div class="col-md-9 col-xs-12 purple">
</div>
</div>
</div>

Related

Bootstrap grid specific layout

how do I make the bootstrap grid like this?
if ≥ 576px:
if < 576px:
Thank you.
Bootstrap's col-xs-$ has the lowest max-width of 768px. I think you will have to add another class to your columns and then specify your CSS rule to that class
For example :
<div class="col-xs-4 smaller-div-class">
Col 1
</div>
<div class="col-xs-4 smaller-div-class">
Col 2
</div>
<div class="col-xs-4 smaller-div-class">
Col 3
</div>
and so on... and add the style in smaller-div-class
#media screen and (max-size<576px){
.smaller-div-class{
width: 100% !important;
}
}
Bootstrap rows each contain 12 columns, and each column should be confined to a row.
Considering you want three columns, you should specify that each has a width of 4 columns, as 12 / 3 = 4. This is done by using col-sm-4 as a class name.
The col-sm- prefix for columns is based on the 'Small' screen sizes, and actually defaults to the exact width you want of 576px:
This can be seen in the following example:
.one {
background: red;
}
.two {
background: blue;
}
.three {
background: green;
}
.col-sm-4 {
height: 50px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
<div class="row">
<div class="col-sm-4 one"></div>
<div class="col-sm-4 two"></div>
<div class="col-sm-4 three"></div>
</div>
Hope this helps! :)
<div class="container">
<div class="row">
<div class="col-sm-4 col-12">
<h2>col1</h2>
</div>
<div class="col-sm-4 col-12">
<h2>col2</h2>
</div>
<div class="col-sm-4 col-12">
<h2>col3</h2>
</div>
</div>
<div class="row">
<div class="col-sm-4 col-12">
<h2>col4</h2>
</div>
<div class="col-sm-4 col-12">
<h2>col5</h2>
</div>
<div class="col-sm-4 col-12">
<h2>col6</h2>
</div>
</div>
</div>

Order and stack 3 columns with bootstrap 4

I have this structure in bootstrap columns:
And I want you to change to a lower resolution, be ordered as follows:
I found how to do it with flexbox here:
Flexbox: reorder and stack columns
But I can not change the entire structure of my project to flexbox, so I want to know if with bootstrap 4, it is possible to do so.
Thank you very much.
My poor test.
#import url( 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css' );
div {
text-align: center;
height: 60px;
}
#left {
background: yellow;
}
#middle {
background: blue;
}
#right {
background: coral;
}
<div class="container">
<div class="row">
<div class="col-sm-3 col-md-3">
<div id="left">COLUMN 1</div>
</div>
<div class="col-sm-6 col-md-6">
<div id="middle">COLUMN 2</div>
</div>
<div class="col-sm-3 col-md-3">
<div id="right">COLUMN 3</div>
</div>
</div>
</div>
You can use the Bootstrap 4 (alpha 6) utility classes to avoid the extra CSS. 1-2-3 becomes 3-2-1 on mobile.
<div class="container">
<div class="row">
<div class="col-sm-8 col-md-6 push-md-3">
<div id="middle">COLUMN 2</div>
</div>
<div class="col-sm-4 col-md-6">
<div class="row">
<div class="col-md-6 pull-md-12 flex-last flex-md-unordered">
<div id="left">COLUMN 1</div>
</div>
<div class="col-md-6">
<div id="right">COLUMN 3</div>
</div>
</div>
</div>
</div>
</div>
http://codeply.com/go/GIcPuzURbs
I assume by "resolution" you mean smaller screen size?
Here's a possible solution that uses some bootstrap push/pull grid utilities to reorder the columns in a medium size viewport, and then rearrange the layout in small size viewport the way you've shown in your diagram. In the small screen view, within a media query I use the css property order to reorder the 1 and 3 columns vertically Hope it gets you on the right track
<div class="container">
<div class="row">
<div class="col-sm-8 col-md-6 push-md-3">
<div id="middle">COLUMN 2</div>
</div>
<div class="col-sm-4 col-md-6">
<div class='row'>
<div id='leftcont' class="col-md-6 pull-md-12">
<div id="left">COLUMN 1</div>
</div>
<div id='rightcont' class="col-md-6">
<div id="right">COLUMN 3</div>
</div>
</div>
</div>
</div>
</div>
CSS:
div {
text-align:center;
height:60px;
}
#left{background:yellow;}
#middle {background:blue;}
#right {background:coral;}
#media (max-width: 768px) {
#leftcont { order: 2; }
#rightcont {
order: 1;
margin-bottom: 1em; }
}
New fiddle
The height of the divs might have to be adjusted for grid breakpoints but since the colored divs were only for a test, i didn't match those to your example
have you tried to pull column 2 for lower resolution?

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>

How does Bootstrap Pull and push work

I am trying to fix a page which wasn't bootstrapped like the illustration. But my col-2, col-3, col-4 don't align with the col 1 and 2. I cannot really understand how pull and push work. I have worked on my mobile layout and it seem fine, but as it goes to desktop, it messing the layout.
My layout becomes this, when I make it go desktop. Misaligned headings and columns under it.
You need to include yellow div-s into row so they won't jump over next line.
.left-box {
height: 290px;
width: 100%;
background: #e66;
margin: 3px;
}
.right-box {
height: 70px;
background: #ee6;
margin: 3px;
}
#media screen and (min-width: 992px) {
.left-box, .right-box {
height: 200px;
}
}
<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-md-2 col-xs-5">
<div class="left-box"></div>
</div>
<div class="col-md-10 col-xs-7">
<div class="row">
<div class="col-md-3"><div class="right-box"></div></div>
<div class="col-md-3"><div class="right-box"></div></div>
<div class="col-md-3"><div class="right-box"></div></div>
<div class="col-md-3"><div class="right-box"></div></div>
</div>
</div>
</div>
</div>
Note: according to bootstrap rules, the statement class="col-md-2 col-sm-5" is the same that class="col-lg-2 col-md-2 col-sm-5 col-xs-12".
Actually you don't need push-pull classes I think. You could use a markup like this:
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="left-box"></div>
</div>
<div class="col-md-6">
<div class="right-box"></div>
<div class="right-box"></div>
<div class="right-box">etc...</div>
</div>
</div>
</div>
Pen: http://codepen.io/anon/pen/yVKgwG

Bootstrap: Full width grid with columns in container

I want to create a full width layout with a blue halft on the left and a red half on the right.
After that I want to add text inside the layout but inside a container.
Is this possible?
EDIT: you can see, that the green container has a different size than the col-6 inside the blue and red half.
* {
color: white;
}
.blue-half {
background: blue;
}
.red-half {
background: red;
}
.green {
background: green;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container green">
I am the normal container!
</div>
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 blue-half">
<div class="container-fluid text-center">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
I am first half of the blue container!
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
I am second half of the blue container!
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 red-half">
<div class="container-fluid text-center">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
I am first half of the red container!
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
I am second half of the blue container!
</div>
</div>
</div>
</div>
</div>
</div>
Variant 2. Divide the container into two parts
You can define a new class for each half of the container. But in this solution you needs to control that the two halves have the same height.
.blue { background: blue; color: white; }
.red { background: red; color: white; }
.container-left-half,
.container-right-half {
padding-right: 15px;
padding-left: 15px;
}
.container-left-half {
margin-right: 0;
margin-left: auto;
}
.container-right-half {
margin-right: auto;
margin-left: 0;
}
#media (min-width: 768px) {
.container-left-half,
.container-right-half {
width: 375px;
}
}
#media (min-width: 992px) {
.container-left-half,
.container-right-half {
width: 485px;
}
}
#media (min-width: 1200px) {
.container-left-half,
.container-right-half {
width: 585px;
}
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 blue">
<div class="container-left-half">
<div class="row">
<div class="col-xs-12">This is a left half of the container. It's blue! This is a left half of the container. It's blue! This is a left half of the container. It's blue! This is a left half of the container. It's blue! This is a left half of the container. It's blue!</div>
</div>
</div>
</div>
<div class="col-xs-6 red">
<div class="container-right-half">
<div class="row">
<div class="col-xs-12">This is a right half of the container. It's red! This is a right half of the container. It's red! This is a right half of the container. It's red! This is a right half of the container. It's red! This is a right half of the container. It's red!</div>
</div>
</div>
</div>
</div>
</div>
Variant 1. Linear-gradient & matryoshka
1) You can use the linear-gradient() function to make two-colored background.
2) Bootstrap has rows and two types of containers:
Use .container for a responsive fixed width container.
Use .container-fluid for a full width container, spanning the entire width of your viewport.
Rows must be placed within a .container (fixed-width) or .container-fluid (full-width) for proper alignment and padding.
3) So you can make a matryoshka:
.container-fluid > .row with linear-gradient > .container > .row with content
Matryoshka is a set of brightly painted hollow wooden dolls of varying sizes, designed to nest inside one another.
4) col-xs-6 is equivalent to col-xs-6 col-sm-6 col-md-6 col-lg-6.
.two-colors {
background: linear-gradient(to right, blue 50%, red 50%);
color: white;
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<div class="container-fluid">
<div class="row two-colors">
<div class="container">
<div class="row">
<div class="col-xs-6">This is a left half of the container. It's blue! This is a left half of the container. It's blue! This is a left half of the container. It's blue! This is a left half of the container. It's blue! This is a left half of the container. It's blue!</div>
<div class="col-xs-6">This is a right half of the container. It's red! This is a right half of the container. It's red! This is a right half of the container. It's red! This is a right half of the container. It's red! This is a right half of the container. It's red!</div>
</div>
</div>
</div>
</div>
Try this
<div class="container-fluid">
<div class="row">
<div class="col-xs-6 blue">
<div class="container">
<!--content-->
</div>
</div>
<div class="col-xs-6 red">
<div class="container">
<!--content-->
</div>
</div>
</div>
CSS
.red{
background: red;
}
.blue{
background: blue;
}
Something like this?
* { color: white; }
.blue-half {
background: blue;
}
.red-half {
background: red;
}
<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-xs-6 col-sm-6 col-md-6 col-lg-6 blue-half">
<div class="container-fluid text-center">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
I am first half of the blue container!
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
I am second half of the blue container!
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 red-half">
<div class="container-fluid text-center">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
I am first half of the red container!
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
I am second half of the red container!
</div>
</div>
</div>
</div>
</div>
</div>
Update
I attempted to create what I was reading from your comment regrading the formatting not being quite right
Update 2
.row-green {
background: green;
color: white;
}
.blue-half {
background: blue;
color: white;
}
.red-half {
background: red;
color: white;
}
.option1 .row .container {
padding: 0;
}
.option2 .container.unindent {
padding: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid option1">
<h3>Option 1</h3>
<p>
This uses a .row .container selector rule to enforece the padding removal on containers nested in rows.
</p>
<div class="row row-green">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
I am the row above!
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 blue-half">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
I am the blue container!
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 red-half">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
I am the red container!
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container-fluid option2">
<h3>Option 2</h3>
<p>
This uses an unindent CSS class on the containers that need to have the padding removed
</p>
<div class="row row-green">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
I am the row above!
</div>
</div>
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 blue-half">
<div class="container unindent">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
I am the blue container!
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-6 col-md-6 col-lg-6 red-half">
<div class="container unindent">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
I am the red container!
</div>
</div>
</div>
</div>
</div>
</div>
Try this:
<div class="container">
<div class="row">
<div class="col-md-6">Left Column</div>
<div class="col-md-6 col-expand">Right Column</div>
</div>
</div>
CSS:
.col-expand {
position: absolute;
background-color: orange;
width: 100%;
right: 0px;
}

Resources