Bootstrap add margin to column - html

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.

Related

Is there a way to make a spacing between div's with shadow?

I'm trying to make 3 divs in one row. Divs are divided for two parts, one with image and other with 3 lines of text.
Divs are with box-shadow style.
When I make all of this i get no spacing between div's, when I add extra margin or padding I get problem when page is resized.
This is what I done most close to what I want, only problem is when i resize browser divs collide with selfs.
When I try to make main 3 div's with breakpoints like col-sm-6-md-4 its crap
I try many ways to do this. This is one of them.. not too nice because with extra padding py-4 and probably this make errors.
I have one working version but with different structure like img is above and text bottom and then its works.
.box1 {
box-shadow: 1px 1px 3px 1px grey;
}
<section>
<div class="container">
<div class="row">
<div class="col-4 py-4">
<div class="row">
<div class="col ">
<div class="row justify-content-center">
<div class="col-11 box1 d-flex">
<div class="box2"><img style="width: 100px; height: 100px;" src="img/icon/m/img.png" alt="a"></div>
<div class="box2">
<p>text</p>
<p>text</p>
<p>text</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-4 py-4">
<div class="row">
<div class="col ">
<div class="row justify-content-center">
<div class="col-11 box1 d-flex">
<div class="box2"><img style="width: 100px; height: 100px;" src="img/icon/m/img.png" alt="a"></div>
<div class="box2">
<p>text</p>
<p>text</p>
<p>text</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-4 py-4">
<div class="row">
<div class="col ">
<div class="row justify-content-center">
<div class="col-11 box1 d-flex">
<div class="box2"><img style="width: 100px; height: 100px;" src="img/icon/m/img.png" alt="a"></div>
<div class="box2">
<p>text</p>
<p>text</p>
<p>text</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<---- below is working code but with other layout what i dont wont -->
<---- below is working code but with other layout what i dont wont -->
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="box1">
<img class="" src="img/icon/m/img.png" alt="a">
<p>text</p>
<p>text</p>
<p>text</p>
</div>
</div>
<div class="col-sm-4">
<div class="box1">
<img class="" src="img/icon/m/img.png" alt="a">
<p>text</p>
<p>text</p>
<p>text</p>
</div>
</div>
<div class="col-sm-4">
<div class="box1">
<img class="" src="img/icon/m/img.png" alt="a">
<p>text</p>
<p>text</p>
<p>text</p>
</div>
</div>
</div>
</div>
Have you tried doing percentage-based margin and widths?
But if you're using bootstrap the columns should automatically have padding between them.
Something like -
.col-sm-4 {
width: 30%
margin: 1.66666667%;
}
Maybe I've misunderstood what you're trying to do.

Customizing bootstrap grid

I need to design grid using bootstrap, like in the picture that I have uploaded.Please help me.
I think something along the lines of
<div class="col-sm-4">
<div class="content-here">
<img src="img1.jpg" />
</div>
</div>
<div class="col-sm-8">
<div class="boxes">
Box 1
</div>
<div class="boxes">
Box 2
</div>
<div class="boxes">
Box 3
</div>
<div class="boxes">
Box 4
</div>
</div>
CSS
.content-here { height: 400px; }
.boxes { float:left; width:50%; height:200px; }
The grid system code might look like this :
<div class="row">
<div class="col-sm-4">
<img src="example.jpg">
</div>
<div class="col-sm-4">
<div class="col-sm-12">
<img src="example.jpg">
</div>
<div class="col-sm-12">
<img src="example.jpg">
</div>
</div>
<div class="col-sm-4">
<div class="col-sm-12">
<img src="example.jpg">
</div>
<div class="col-sm-12">
<img src="example.jpg">
</div>
</div>
</div>
After that, you can specify the width and height of each image. If you want your image to take a full width (means taking all space of the column), you can set width:100%.

Side bar has undefined height and misplaced image

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>

How to overlap panel from one row to another row?

I have these panels inside different rows. To easily show my problem, and my desired output, here's a visual...
At the left side is the problem I encounter, and at the right side is the desired output. I was wondering how it's possible to make the right panel overlap to the other row.
My html's structured something like this, which is all inside a .container-fluid(if that contributes to the problem)...
<div class="row">
<div class="col-md-6">
<div class="panel"> <!-- top-left panel --> </div>
</div>
<div class="col-md-6">
<div class="panel"> <!-- right panel --> </div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="panel"> <!-- bottom-left panel --> </div>
</div>
</div>
I'm using bootstrap.
p.s. sorry for the html "sample", not familiar yet on how to use the html snippet
Use flex
.flex{
display:flex;
}
.flex-1{
flex:1;
}
.height-50{
height:50px;
}
.margin-r-15{
margin-right:15px;
}
.border-1px{
border:1px solid black;
}
<div class="flex">
<div class="flex-1 margin-r-15">
<div class="height-50 border-1px" >
</div>
<div class="height-50 border-1px">
</div>
</div>
<div class="flex-1 border-1px">
</div>
</div>
You can code left div's in one wrapper and right one in another.
HTML
<div class="row">
<div class="col-md-6">
<div class="panel">
//top left panel
</div>
<div class="panel">
// bottom left panel
</div>
</div>
<div class="col-md-6">
<div class="panel">
// right panel
</div>
</div>
</div>
According to your visual above html will be fine but heights are not managed in this.
If you wish to have same height of right box according to left main box then use follwing code
HTML
<div class="row main">
<div class="col-md-6 inner">
<div class="panel">
//top left panel
</div>
<div class="panel">
// bottom left panel
</div>
</div>
<div class="col-md-6 inner">
<div class="panel">
// right panel
</div>
</div>
</div>
CSS
.main{
display:flex;
}
Please try like this:
<div class="row">
<div class="col-md-8">
<div class="row">
<div class="col-md-12"></div>
</div>
<div class="row">
<div class="col-md-12"></div>
</div>
</div>
<div class="col-md-3">
<div class="row">
<div class="col-md-12"></div>
</div>
</div>
</div>
Please try this:
<div class="row">
<div class="col-lg-8 col-md-8 col-xs-12 col-s-12">
<div class="col-lg-12 col-md-12">
//Your Content Here
</div>
<div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
//Your Content Here
</div>
</div>
<div class="col-lg-4 col-md-4 col-xs-12 col-sm-12">
<div class="col-lg-12 col-md-12 col-xs-12 col-sm-12">
//Your Content Here
</div>
</div>
</div>
If you can use separate columns (as shown in Gaurav's answer) that will work. If the height of the panels is unknown (variable) here isn't really a simple way. Another option is to put all your cols in a single row and use CSS3 column-width..
.row {
-moz-column-width: 50em;
-webkit-column-width: 50em;
-moz-column-gap: .1em;
-webkit-column-gap: .1em;
}
.col-md-6 {
float:none;
display: inline-block;
margin: .1em;
width: 100%;
}
http://www.bootply.com/6ynLAwenzq

How to make a div span two rows (only on mobile layout)?

I have a responsive web layout based on bootstrap. I have Glyphs, titles and text. These are my two layouts:
[1A] [1B] [1C]
[2A] [2B] [2C]
[3A] [3B] [3C]
This is the layout for small screens.
[1A] [2A]
[3A]
[1B] [2B]
[3B]
[1C] [2C]
[3C]
This code makes the first layout, but how do I achieve the second responsively?
EDIT:
I have this:
From this code:
CSS:
.green-box {
background: #3DBEAF;
border: 5px solid #e7e7e7;
border-radius: 20px;
margin-top: 10%;
margin-bottom: 10%;
padding-top: 10px;
padding-bottom: 15px;
margin-left: 2.77778%
}
#media (max-width: 769px) {
.mob-hide{
display: none;
}
.green-box{
margin-left: 20px;
margin-right: 20px;
vertical-align: middle;
}
}
HTML:
<div class="container text-center">
<div class="col-xs-12 col-sm-3 green-box eqheight1">
<div class="glyphicon-ring"> <span class="glyphicon glyphicon-bullhorn glyphicon-bordered" /></div>
<div class="col-xs-9 col-sm-12">
<h3>Revolutionary</h3>
</div>
<div class="col-xs-9 col-sm-12">
<p class>Knowing when to change a gas bottle isn't always easy so many people buy a back-up or risk running out unexpectedly is a real pain - it might leave you cold or with hungry in-laws, either way it will spoil your day. Meet Gas-Sense!</p>
</div>
</div>
<div class="col-sm-1 margin mob-hide"></div>
<!-- Other two boxes -->
</div
How do I get the glyph on the left, and centered in the middle vertically of the title text block?
Just going off your diagram:
<div class="container">
<div class="col-sm-12 col-md-4">
<div class="col-sm-3 col-md-12">The X icon in the diagram</div>
<div class="col-sm-9 col-md-12">
The article text
</div>
</div>
</div>
You need group each icon, text and heading together, then add some classes for col-xs-*:
http://codepen.io/anon/pen/RreRrN
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="col-xs-3 col-sm-12">
<div class="glyphicon-ring"> <span class="glyphicon glyphicon-bullhorn"/></div>
</div>
<div class="col-xs-9 col-sm-12">
<h2>Title 1</h2>
<p>Text 1</p>
</div>
</div>
<div class="col-sm-4">
<div class="col-xs-3 col-sm-12">
<div class="glyphicon-ring"> <span class="glyphicon glyphicon-ok"/></div>
</div>
<div class="col-xs-9 col-sm-12">
<h2>Title 2</h2>
<p>Text 2</p>
</div>
</div>
<div class="col-sm-4">
<div class="col-xs-3 col-sm-12">
<div class="glyphicon-ring"> <span class="glyphicon glyphicon-phone"/></div>
</div>
<div class="col-xs-9 col-sm-12">
<h2>Title 3</h2>
<p>Text 3</p>
</div>
</div>
</div>
</div>