Im a little confused why bootstrap wont apply left and right margins to the columns, all i want is a simple row with 3 columns that have like 20px horizontal margin in between each other. If try to do that bootstrap simply clips one of the divs to the next line.
html
<div class="container">
<div class="row">
<div class="col-md-4"><p>Box 1</p></div>
<div class="col-md-4"><p>Box 1</p></div>
<div class="col-md-4"><p>Box 1</p></div>
</div>
</div>
css
.col-md-4 {
background-color: tomato;
margin: 20px 5px;
}
Left and right margins to the columns would destroy Bootstrap's grid behaviour. Don't modify Bootstrap's classes. Add your own classes instead.
In your example put an extra <div> in the column. And give it a margin.
HTML
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="spacer">
<p>Box 1</p>
</div>
</div>
<div class="col-md-4">
<div class="spacer">
<p>Box 1</p>
</div>
</div>
<div class="col-md-4">
<div class="spacer">
<p>Box 1</p>
</div>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="spacer">
<p>Box 1</p>
</div>
</div>
<div class="col-md-4">
<div class="spacer">
<p>Box 1</p>
</div>
</div>
<div class="col-md-4">
<div class="spacer">
<p>Box 1</p>
</div>
</div>
</div>
</div>
CSS
.spacer {
background-color: tomato;
margin: 20px 5px;
}
Demo
for a little more spacing you could do:
<div class="col-md-3 col-md-offset-1"><p>Box 1</p></div>
<div class="col-md-3 col-md-offset-1"><p>Box 1</p></div>
<div class="col-md-3 col-md-offset-1"><p>Box 1</p></div>
Bootstrap slips one in new row because it column layout is 12 columns max.
When you have 3 divs * (4 col width + margin-right) you excess the provided 12 columns.
You can set your div a little bit thinner, i.e. 3 medium bootstrap columns, like this:
<div class="col-md-3 custom-box"><p>Box 1</p></div>
<div class="col-md-3 custom-box"><p>Box 1</p></div>
<div class="col-md-3 custom-box"><p>Box 1</p></div>
and apply your css rule like this:
.custom-box{
margin-right: 20px 5px!important;
background-color: tomato;
}
here is a FIDDLE
Related
Looking under the hood of Bootstrap gutters led me to realize that the space between columns is added using padding, not a margin.
This is problematic because if you want to use Bootstrap 5's default flexbox to get your columns of equal height, you have to apply things like box shading or background to the column itself. This means that a gutter using padding gives you an awkward white gap within your column, rather than space between the columns.
Here's a fiddle that demonstrates my issue:
.red {
background-color: red;
color: white;
}
.blue {
background-color: blue;
color: white;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.0/dist/css/bootstrap.min.css">
<h2>
No Gutters
</h2>
<div class="container px-5">
<div class="row ">
<div class="col-6 red">
<p>Column content</p>
<p>is different</p>
<p>heights.</p>
</div>
<div class="col-6 blue">
<p>See? Shorter.</p>
</div>
</div>
</div>
<h2>
Gutters via Padding
</h2>
<div class="container px-5">
<div class="row gx-4">
<div class="col-6 red">
<p>Column content</p>
<p>is different</p>
<p>heights.</p>
</div>
<div class="col-6 blue">
<p>See? Shorter.</p>
</div>
</div>
</div>
<h2>
Gutters fine but BG Wonky
</h2>
<div class="container px-5">
<div class="row gx-4">
<div class="col-6">
<div class="red">
<p>Column content</p>
<p>is different</p>
<p>heights.</p>
</div>
</div>
<div class="col-6">
<div class="blue">
<p>See? Shorter.</p>
</div>
</div>
</div>
</div>
Is there any way to get space between columns that acts as a margin not padding? If you add a straight-up margin it pushes the whole grid layout out of whack.
I feel like this should be easy, but I'm trying to get my .temp and .city divs to be side-by-side, but they're stacking vertically instead.
I've tried changing the size of the columns, but they always stack on top of each other. Any ideas?
<div class="col-lg" id="col2">
<div class="row">
<div class="col-lg">
<div class="wind"></div>
</div>
</div>
<div class="row">
<div class="col-lg" id="col3">
<div class="temp"></div>
<div class="city"></div>
</div>
</div>
</div>
You can wrap temp div and city div into 2 different columns. Check this Bootstrap4 Example.
.wind,
.temp,
.city {
height: 50px;
border: 1px solid red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" rel="stylesheet" />
<div class="col-sm" id="col2">
<div class="row">
<div class="col-lg">
<div class="wind"></div>
</div>
</div>
<div class="row">
<div class="col-lg" id="col3">
<div class="temp"></div>
</div>
<div class="col-lg" id="col3">
<div class="city"></div>
</div>
</div>
You can rearrange your html code to this format.
<div class="row">
<div class="col-lg" id="col2">
<div class="col-lg">
<div class="wind"></div>
</div>
</div>
<div class="col-lg" id="col3">
<div class="temp"></div>
<div class="city"></div>
</div>
</div>
You should edit your code to this, making the second row have two columns.
<div class="col-lg" id="col2">
<div class="row">
<div class="col-lg">
<div class="wind"></div>
</div>
</div>
<div class="row">
<div class="col temp"></div>
<div class="col city"></div>
</div>
</div>
I'm sure I'm overcomplicating this in my head, but is the following layout possible using the standard bootstrap 3 grid system?
Header and sub header can fill 12 columns. Then Image, probably fixed height, spans 8-col then a side bar which spans 4-col. The problem is the side bar has an undefined height and the underneath of the image is content.
So far got something like:
<div class="col-xs-12">
<h1>Header</h1>
</div>
<div class="row">
<div class="col-md-8">
image
</div>
<div class="col-md-4">
Navigation down right
</div>
<div class="col-sm-8">
Content
</div>
</div>
Layout
According to your image
You should use the following layout (Click the "Full page" button to see it in action. Also, ignore the CSS. It's just for testing purposes):
#import url(https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css);
[class*='col-'] > div:not(.row) {
background: #DDD;
margin: 0.25em 0;
padding: 0.5em;
text-align: center;
height: 5em;
}
.red [class*='col-'] > div:not(.row) {
background: #C55;
color: #FFF;
height: auto;
}
[class*='col-sm-4'] > div:not(.row) {
height: 9em;
}
<div class="container">
<div class="red row">
<div class="col-sm-12">
<div>HEADER</div>
</div>
<div class="col-sm-8">
<div>SUB HEADER</div>
</div>
</div>
<div class="row">
<div class="col-sm-8">
<div class="row">
<div class="col-sm-12">
<div>IMAGE</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div>LEFT COL</div>
</div>
<div class="col-sm-6">
<div>RIGHT COL</div>
</div>
</div>
</div>
<div class="col-sm-4">
<div>SIDEBAR</div>
</div>
</div>
</div>
Essentially you want a nested row with 6 wide columns for a 12 column grid layout.
Bootstrap row has only twelve spans. I see that 8 + 4 + 8 = 20 > 12, so the "content" div will be at a new line...
And you can't put col-sm-x with col-md-x in the same row...
My suggestion: split into two rows
<div class="col-xs-12">
<h1>Header</h1>
</div>
<div class="row">
<div class="col-md-8">
image
</div>
<div class="col-md-4">
Navigation down right
</div>
</div>
<div>
<div class="col-sm-8">
Content
</div>
</div>
But If you want all of it in the same row:
<div class="col-xs-12">
<h1>Header</h1>
</div>
<div class="row">
<div class="col-md-5">
image
</div>
<div class="col-md-2">
Navigation down right
</div>
<div class="col-md-5">
Content
</div>
</div>
And if you want a side section, you can cascade rows:
<div class="col-xs-12">
<h1>Header</h1>
</div>
<div class="row">
<div class="col-md-8">
<div class="row">
<div class="col-md-12">
Image
</div>
</div>
<div class="row">
<div class="col-md-12">
Content
</div>
</div>
</div>
<div class="col-md-4">
Navigation down right
</div>
</div>
I'm trying to have a nice grid of items on my site using Bootstrap 3 grid, while each item has a different height.
The problem is that i get different spaces between the items.
Forgive me for the long code, I had to write 6 items in order to show the problem. Once you read the first you'll notice it repeats but with different length due to different item description.
<div class="container">
<div class="row-fluid">
<div class="col col-sm-6 col-md-4">
<div class="result-padder">
<div class="box">
<p class="boxTitle">vendor1</p>
<p class="boxDescription">Description of vendor1</p>
</div>
</div>
</div>
<div class="col col-sm-6 col-md-4">
<div class="result-padder">
<div class="box">
<p class="boxTitle">vendor2</p>
<p class="boxDescription">Description of vendor2 which is longer and the layout takes more than one line...</p>
</div>
</div>
</div>
<div class="col col-sm-6 col-md-4">
<div class="result-padder">
<div class="box">
<p class="boxTitle">vendor3</p>
<p class="boxDescription">Description of vendor3</p>
</div>
</div>
</div>
</div>
<div class="row-fluid">
<div class="col col-sm-6 col-md-4">
<div class="result-padder">
<div class="box">
<p class="boxTitle">vendor4</p>
<p class="boxDescription">Description of vendor4</p>
</div>
</div>
</div>
<div class="col col-sm-6 col-md-4">
<div class="result-padder">
<div class="box">
<p class="boxTitle">vendor5</p>
<p class="boxDescription">Description of vendor5</p>
</div>
</div>
</div>
<div class="col col-sm-6 col-md-4">
<div class="result-padder">
<div class="box">
<p class="boxTitle">vendor6</p>
<p class="boxDescription">Description of vendor6</p>
</div>
</div>
</div>
</div>
</div>
The result is that the first row is set right but the second row comes out bad.
I want the spaces between all items to be the same, making it much more fluid.
Note: the heights of the items change all the time, so it has to work with all set of heights.
Take a look at it, you need to resize the result window to max in order to see the problem: http://jsfiddle.net/asafusan/09egpzkj/6/
How can I fix it?
I'm a rookie in programing so please explain extensively.
Thanks
i happen some time if you put less data then other so it become some irregular shape,
for this you have to give a fix height to your div, but it cause one issue that is it will be in same height in mobile or tablet as your applied,
so for this you have use media queries for mobile version
i am declaring another class that is grid, and give static height
Your code looks good, I would use a visual border to see the code. I created a mockup for you here
[http://www.bootply.com/Pzn15AfwyA][1]
.container {
border: 1px solid blue;
}
.result-padder {
border: 1px solid red;
margin-bottom: 10px;
}
<div class="wrapper">
<div class="container">
<div class="row">
<div class="col-md-4 col-lg-4">
<div class="result-padder">
<h1>vendor1</h1>
<p>Description of vendor1</p>
</div>
</div>
<div class="col-md-4 col-lg-4">
<div class="result-padder">
<h1>vendor1</h1>
<p>Description of vendor1</p>
</div>
</div>
<div class="col-md-4 col-lg-4">
<div class="result-padder">
<h1>vendor1</h1>
<p>Description of vendor1</p>
</div>
</div>
</div><!-- .row 1 -->
<div class="row">
<div class="col-md-4 col-lg-4">
<div class="result-padder">
<h1>vendor1</h1>
<p>Description of vendor1</p>
</div>
</div>
<div class="col-md-4 col-lg-4">
<div class="result-padder">
<h1>vendor1</h1>
<p>Description of vendor1</p>
</div>
</div>
<div class="col-md-4 col-lg-4">
<div class="result-padder">
<h1>vendor1</h1>
<p>Description of vendor1</p>
</div>
</div>
</div><!-- .row 2 -->
</div>
</div>
[1]: http://www.bootply.com/Pzn15AfwyA
This is probably very simple, but my mind is getting tangled with trying to work this out. Spent an hour or so searching this up and it still isn't working.
My HTML code...
<div class="section-container light-bg">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 style="text-align:center;">Main Title Right Here</h2>
<h4 style="text-align:center;">Slogan text underneath</h4>
</div>
<div class="col-md-3 light-panel">
<h3>TITLE</h3>
<p>TEXT</p>
</div>
<div class="col-md-3 light-panel">
<h3>TITLE</h3>
<p>TEXT</p>
</div>
<div class="col-md-3 light-panel">
<h3>TITLE</h3>
<p>TEXT</p>
</div>
<div class="col-md-3 light-panel">
<h3>TITLE</h3>
<p>TEXT</p>
</div>
</div>
</div>
CSS
.section-container.light-bg {
background-color: #F5F5F5;
color: #444444;
}
.section-container .light-panel {
background-color: #ffffff;
border-radius:10px;
}
This is currently creating a row with 4 columns that are styled slightly.
Any help or explanation of how to correctly do this using Bootstrap 3 would be greatly appreciated :)
Demo Fiddle
The best approach is to add an inner container, then padding on the columns. This ensures Bootstraps functionality remains as intended.
HTML
<div class="section-container light-bg">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2 style="text-align:center;">Main Title Right Here</h2>
<h4 style="text-align:center;">Slogan text underneath</h4>
</div>
<div class="col-md-3 light-panel">
<div class='inner'>
<h3>TITLE</h3>
<p>TEXT</p>
</div>
</div>
<div class="col-md-3 light-panel">
<div class='inner'>
<h3>TITLE</h3>
<p>TEXT</p>
</div>
</div>
<div class="col-md-3 light-panel">
<div class='inner'>
<h3>TITLE</h3>
<p>TEXT</p>
</div>
</div>
<div class="col-md-3 light-panel">
<div class='inner'>
<h3>TITLE</h3>
<p>TEXT</p>
</div>
</div>
</div>
</div>
CSS
.section-container.light-bg {
background-color: #F5F5F5;
color: #444444;
}
.inner {
background-color: #ffffff;
border-radius:10px;
padding:10px;
}
.col-md-3 {
padding:10px;
}
Alternatively
You can use calculated width/margins., no change to your HTML necessary.
E.g. the width of col-md-3 is 100/4=25%. Therefore you can reduce this, say to 20%, and allocate the remaing 5% to your margins.
.col-md-3 {
width:20%;
margin:0 2.5%;
}
I was facing the same issue; and the following worked well for me. Hope this helps someone landing here:
<div class="row">
<div class="col-md-6">
<div class="col-md-12">
Set room heater temperature
</div>
</div>
<div class="col-md-6">
<div class="col-md-12">
Set room heater temperature
</div>
</div>
</div>
This will automatically render some space between the 2 divs.