how to make this layout in bootstrap3? - html

I tried using the following code, but can't make equal margin to each box
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 box"></div>
</div>
<div class="row">
<div class="col-xs-6 box"></div>
<div class="col-xs-6 box">
<div class="row">
<div class="col-xs-12 box"></div>
</div>
<div class="row">
<div class="col-xs-12 box"></div>
</div>
</div>
</div>
</div>

Space between rows
There isn't anything built-in (for version 3 according to the provided tag on question) for that much vertical space, so you'll want to stick with a custom class.
HTML
<div class="row vertical-space">
...
</div>
CSS
.vertical-space{
margin-bottom: 15px;
}
Please note that, if you are putting those images as CSS background-image for the <div class="row">, then you need to replace padding width margin in the above snippet.
Space between columns
You should work with padding on the inner container to gain space between columns.
HTML
<div class="col-xs-6 box">
<div class="row horizontal-space">
...
</div>
</div>
CSS
.horizontal-space{
padding: 0 15px;
}

All bootstrap columns have 15 pixel left and right padding and the rows have -15 pixel margins.
This means that by default the gap between columns will be 30 pixels but the columns at either end will have their outer edges offset into the rows.
What you can do is remove the right (or left) padding from each of your boxes, however you would need to adjust the row to make sure that the padding is compensated for or it will cause horizontal scrolling. You'd also need to add 15 pixels to the bottom of each box to get your vertical gaps. See below.
<div class="container-fluid">
<div class="row box-row">
<div class="col-xs-12 box"></div>
</div>
<div class="row box-row">
<div class="col-xs-6 box"></div>
<div class="col-xs-6 box">
<div class="row box-row">
<div class="col-xs-12 box"></div>
</div>
<div class="row box-row">
<div class="col-xs-12 box"></div>
</div>
</div>
</div>
</div>
And the css would be like this.
.box-row {
margin-right:0;
}
.box {
padding-right:0;
padding-bottom:15px;
}

Related

How to make 4 columns in bootstrap grid break to two then one column

Here is my bootstrap code so far:
<div class="container-flex">
<div class="row">
<div class="col-lg-3">1</div>
<div class="col-lg-3">2</div>
<div class="col-lg-3">3</div>
<div class="col-lg-3">4</div>
</div>
</div>
A simple 4 column setup. Currently it breaks into single column on large (lg class) breakpoint. Is there any way I can set it up so it breaks into two columns on large breakpoint then into one column on medium (md class ) breakpoint? I've been looking over bootstrap tutorials and can't find any solution.
Here's my jsfiddle: https://jsfiddle.net/noe562h0/
Try this
<div class="container-flex">
<div class="row">
<div class="col-12 col-md-6 col-lg-3">1</div>
<div class="col-12 col-md-6 col-lg-3">2</div>
<div class="col-12 col-md-6 col-lg-3">3</div>
<div class="col-12 col-md-6 col-lg-3">4</div>
</div>
</div>
Here are Bootstrap 4 grid references Bootstrap and w3schools.com documentation.
If you want to break differently, you have to use different breakpoint. Like this:
<div class="container-flex">
<div class="row">
<div class="col-lg-6 col-md-12">1</div>
<div class="col-lg-6 col-md-12">2</div>
<div class="col-lg-6 col-md-12">3</div>
<div class="col-lg-6 col-md-12">4</div>
</div>
</div>
Check the below fiddle:
Grid Breakdown
https://jsfiddle.net/x4rjp1gq/
<div class="container-flex">
<div class="row">
<div class="col-lg-3">
<div class='col'>1</div>
<div class='col'>2</div>
</div>
<div class="col-lg-3">
<div class='col'>3</div>
<div class='col'>4</div>
</div>
</div>
</div>
.row {
background: #f8f9fa;
margin-top: 20px;
}
.col {
border: solid 1px #6c757d;
text-align:center;
}

Bootstrap grid stacked columns not filling up the whole width

I'm having issues with the following markup. The columns from the last row do not fill up the whole width even though the container is fluid and the sum of their classes is 12.
<div class="container-fluid">
<div class="row" id="header">
<h1>Title</h1>
</div>
<div class="row" id="ndHeader">
<h2>Categories </h2>
</div>
<div class="row">
<div class="col-xs-6 col-sm-3" id="sidebar">.col-xs-6 .col-sm-3</div>
<div class="col-xs-6 col-sm-9">
<div class="clearfix hidden-sm-up"></div>
<div class="row tileRow">
<div class="col-xs-4 col-sm-3 tile">
<div class="tileContent"> asd </div>
</div>
<div class="col-xs-4 col-sm-3 tile">
asd asd asdasdasdaddddddddddddddddddddddddddddddddddddddddddddddddddd
</div>
<div class="col-xs-4 col-sm-3 tile">
asd asd asdasdasdaddddddddddddddddddddddddddddddddddddddddddddddddddd
</div>
</div>
</div>
</div>
</div>
You can see the live example : http://www.bootply.com/GsJbodLFwb#
The columns are using the correct width. In the last row you have two main divs, a col-sm-3 and a col-sm-9. The col-sm-9 is correctly using up 75% of the available space. The div that has the col-sm-3 attached to it has some css overwriting its width. You need to remove the following code to get that back to spanning the full 25% that it should be:
#sidebar {
background-color:green;
//width:15em; <-- remove this
height:100%;
}
Also, the three divs inside of your tile row only add up to 9 at the sm size. You'll want to change those to col-sm-4 or just remove them altogether as the col-xs-4 will do the same thing.
You are setting widths for these 2 cells
<div class="col-xs-6 col-sm-3" id="sidebar">...</div>
<div class="col-xs-6 col-sm-3">...</div>
First one has a width: 15em; and the second one is width: 75%; which is causing that row width to behave oddly. If you need a custom width table i suggest not using the bootstrap rows & cells and just make your own.
<div class="row">
<div class="col-xs-12 col-sm-12">
*my custom table or divs here*
</div>
</div>

Grid with container-fluid and container in Bootstrap 3

I have been using html/css for a while now. And I have never ran into this kind of grid problem with Bootstrap 3. I am trying to find a way to combine a 50% width (inside a <div class="container-fluid">) with a 50% width div (inside a <div class="container">). Like the grid in the following picture:
Example of the template
Yellow overlay: <div class="container"></div>
The problem is that they won't work together cause of the widths.
So how do I simulate this?
<section>
<div class="container-fluid">
<div class="col-sm-12 col-md-6 no-padding"></div>
<div class="container">
<p>content</p>
</div>
</div>
<div class="col-sm-12 col-md-6 no-padding photo"></div>
</div>
</section>
If I'm understanding what you're trying to achieve, there are a couple of problems. Firstly, you still need a row div to wrap the columns, which is in turn nested in the container. Also, by default, the container would have some padding, so that would need to be removed with some basic CSS as well.
Here is the HTML structure
<div class="container-fluid">
<div class="row">
<div class="col-lg-6" id="left">
Left Side
</div>
<div class="col-lg-6" id="right">
Right Side
</div>
</div>
</div>
Also, here's a live example you can play with: http://www.bootply.com/MKe7aJwKuc
Let me know if I missed the mark on what you're trying to do and I can try to rework it and help you out.
Should be this schema
<section>
<div class="container-fluid">
<div class="col-sm-12 col-md-6 no-padding"></div>
<div class="col-sm-12 col-md-6 no-padding photo"></div>
<div class="container">
<div class= "row">
<div class="col-sm-12 col-md-6 no-padding">Content</div>
<div class="col-sm-12 col-md-6 no-padding photo"></div>
</div>
</div>
</div>
</section>
on Bootstrap 4
<div class="container">
<div class="row">
<div class="col-lg-6">
<div class="elem left">Left Side</div>
</div>
<div class="col-lg-6">
<div class="elem right">Right Side</div>
</div>
</div>
</div>
sass
#mixin fluidwidth($widths: $container-max-widths, $breakpoints: $grid-breakpoints) {
#each $breakpoint, $container-max-width in $widths {
#include media-breakpoint-up($breakpoint, $breakpoints) {
width: calc(100% + ((100vw - #{$container-max-width})/2) );
}
}
}
.elem.right{#include fluidwidth;}

Centering bootstrap responsive columns

I'm looking for the optimal method of centering a group of responsive bootstrap columns inside a row.
<li class="row hazRow">
//center this to the middle of the row
<div class="col-xs-3">
<img class="icon" href="#" title="icon" src="img/table/icon.svg">
</div>
<div class="col-xs-4">
<p>Title</p>
</div>
//end center
</li>
I was thinking of using just blank col either side, but feels like a waste and would not be able to center odd column(s) widths like 7.
I also tried wrapping the columns in a div with class of .center-block and .text-center, but this did not change the positions.
Should I abandon responsive bootstrap grids for this?
How can I center these columns?
You can accomplish this by borrowing slightly from Foundation
As others have suggested the first step is to nest your columns in an 'outer' column:
<div class="row">
<div class="col-xs-7 centered">
<div class="row hazRow">
<div class="col-xs-5">
icon.svg
</div>
<div class="col-xs-7">
<p>Title</p>
</div>
</div>
</div>
</div>
(Notice the outer column has your desired width of 7 and the inners now add up to 12)
Then add css to stop the outer column from floating and center it:
.centered {
float:none;
margin:0 auto;
}
jsfiddle example
This is where we use nested row and col classes...
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="row">
<div class="col-md-4"></div>
<div class="col-md-8"></div>
</div>
</div>
</div>
For odd columns: (if you need 9 colums)
<div class="row">
<div class="col-md-10 col-md-offset-1">
<div class="row">
<div class="col-md-4 col-md-offset-1"></div>
<div class="col-md-6"></div>
</div>
</div>
</div>
This will give you an approx 9 column width.
Try this...
<div class="col-xs-6 text-right">
<img class="icon" href="#" title="icon" src="img/table/icon.svg">
</div>
<div class="col-xs-6 text-left">
<p>Title</p>
</div>

Bootstrap grid nesting columns issue

What I am trying to do is to have two columns of 3 nested pink squares each, at the large and med settings, then on small screen tablet a single column with 3 pink squares then another single column with 3 pink squares under that. Then at the xs mobile level I'm trying to again have two columns but with 1 column of nested pink squares in each. I thought this is what my css is requesting, but that's not what is happening :( What am I doing wrong here?
Here's a plunker
Here's the html:
<div class="container">
<div class="row">
<div class="col-xs-6 col-sm-12 col-md-6 col-lg-6"><h4>My Subtitle</h4>
<div ng-repeat="x in things">
<div class="col-xs-6 col-sm-4 col-md-4">
<div class="cube">
<b>{{x.title}}</b> </br> {{x.content}}
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-12 col-md-6 col-lg-6"><h4>My Subtitle 2</h4>
<div ng-repeat="x in things2">
<div class="col-xs-6 col-sm-4 col-md-4">
<div class="cube">
<b>{{x.title}}</b> </br> {{x.content}}
</div>
</div>
</div>
</div>
</div>
It seems like you're confused by the number at the end of the class.
While nesting .col-xs-6 inside another .col-xs-6, you will get a column which takes only 50% of the width.
It's a primary principle of 12 column grid. Divide 100% / 12 = 8.33333333333% and you will get width property of a single column in percents, please have in mind that the width in percents is calculated according to the parent width.
Bootstrap's grid is not informative while nesting.
Eg. think of .col-xs-6 as width: 50%;, .col-xs-4 is width: 33.33333%;
halfzebra is right. If you you nest columns you always have new 12 columns inside another one.
<div class="col-md-6">
<div class="row">
<div class="col-md-12">
This will fill col-md-6
</div>
</div>
</div>
And like in example above I always like to use rows when Im starting one.
I don't know if I got you right but you could do something like this:
<div class="container">
<div class="row">
<div class="col-xs-6 col-sm-12 col-md-6 col-lg-6">
<div class="row">
<div class="col-md-12">
<h4>My Subtitle</h4>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-4" ng-repeat="x in things">
<div class="cube">
<b>{{x.title}}</b> </br> {{x.content}}
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-12 col-md-6 col-lg-6">
<div class="row">
<div class="col-md-12">
<h4>My Subtitle 2</h4>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4 col-md-4" ng-repeat="x in things2">
<div class="cube">
<b>{{x.title}}</b> </br> {{x.content}}
</div>
</div>
</div>
</div>
</div>
</div>
Keep in mind that your red boxes are not always fitting in to the columns. I changed width to 100% so you can see how columns are acting.
Plunker: http://plnkr.co/edit/EE4eWrrGIJ0lFdPBcq7T?p=preview