I am using the following to create a 3 columns layout feel to my website:
<div>
<div class="foo col-md-4">
</div>
<div class="foo col-md-4">
</div>
<div class="foo col-md-4">
</div>
<div class="foo col-md-4">
</div>
</div>
The above works great, and no matter how many foo items I added, it will format it to three columns layout automatically. However, I wanted to add a boxed feeling to each of the foo item, so that it does not look like that they're attached to each other. To achieve this, I added margin to the foo class:
.foo
{
margin: 3px 3px 3px 3px;
}
Adding the above, changes the layout become a two column layout.
My goal is to replicate responsive boxed layout, just like one we find in google plus.
Since the Bootstrap cols already having padding, you could make the content of your columns boxed.. For example, the panel creates a boxed effect.. No additional CSS required:
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Title</div>
<div class="panel-body">Content here..</div>
</div>
</div>
Demo on Bootply: http://bootply.com/96277
Also, you may be interest in this Bootstrap Google+ project:
http://iatek.github.io/bootstrap-google-plus/
http://jsbin.com/akaQufU/3
Put a div inside the col-* this can be done.
CSS
body {background:#eee}
/* demo */
.container {padding:3%;}
/* put a div inside .foo style for demo */
.foo > div {
background:#fff;
margin-bottom:4px;
padding:2%
}
/* adjust row margins */
.row.foo-row {
margin-left: -2px;
margin-right: -2px;
}
/* adjust padding */
.row.foo-row .col-sm-4,
.row.foo-row .col-md-4,
.row.foo-row .col-lg-4 {
padding-left: 2px;
padding-right: 2px;
}
HTML
<div class="container">
<div class="row foo-row">
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
<div class="foo col-md-4">
<div>
something
</div>
</div>
</div>
</div>
how about adding inset border instead
.foo
{
border-color:transparent;
border:inset 3px;
}
because margin will be calculated as a column extra width
anyway if you want to seperate them without using borders , then just use padding
.foo
{
padding:3px 3px 3px 3px;
}
Your columns should already spaced properly by your code and bootstrap's grid system, you just need need to added a margin to the bottom to stop them touching.
margin-bottom: 3px;
The problem you had with it converting to a 2 column was because you were adding side margin of 3px as well, which throws bootstraps grid system out.
You can't use padding (well) because bootstrap uses it for spacing and that will be more pain than gain.
Related
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
I'm trying to make some space / gap between 2x col-sm-6 inside an row. Have tried some methods from earlier posts here from Stack Overflow, but none seem to make the right result.
What I have tried:
<div class="row">
<div class="col-sm-6">
<div class="col-md-12 contentpage3">
</div>
</div>
<div class="col-sm-6">
<div class="col-md-12 contentpage3">
</div>
</div>
</div>
Well... this creates the right spacing, but then the left and right sides are not allign with the rest of the page content. To help you guys understand what I'm trying to explain, here is a picture.
Here you can see that the upper white content, the width is what I'm trying to keep for all the elements inside the page. I know its because the extra div I added, because the following code is producing the upper white content box you see in the picture, but then there is no spacing. Have also tried with col-md-5 and an offset of 2 but this creates too much spacing.
<div class="row">
<div class="col-sm-6 contentpage3">
</div>
<div class="col-sm-6 contentpage3">
</div>
</div>
What am I doing wrong?
You can do something like this.
All .col-* elements should be inside row elements.
All .col-* elements should contain content, not be content.
.example {
padding-bottom: 15px;
background: #ccc;
}
.example > .row > div {
margin-top: 15px;
}
.example .inside {
height: 50px;
background: #fff;
border: 1px solid #eee;
}
<div class="container-fluid example">
<div class="row">
<div class="col-xs-12">
<div class="inside"></div>
</div>
</div>
<div class="row">
<div class="col-xs-6">
<div class="inside"></div>
</div>
<div class="col-xs-6">
<div class="inside"></div>
</div>
</div>
</div>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
A picture is worth a thousand words so...
Structure:
<div class="row">
<div class="col-lg-2 col-md-3 col-sm-4 text-center column-fix">
<div class="row-fluid">
<div class="row-fluid">
<div class="image">
<img src.... />
</div>
</div>
<div class="row-fluid">
<div class="category-link">
<a href...></a>
</div>
</div>
</div>
</div>
...
</div>
Output:
Basically, when a column is higher than the others, it causes the order to break. I understand this is how floats work, but I need a nice and clean solution for this. At the moment, this is my workaround:
.column-fix {
float: none !important;
display: inline-block !important;
margin: 0 -0.125em !important;
vertical-align:top;
}
And this is the output I get with the fix:
Is there a nice solution that will override all columns in all widths without setting a custom class to every element? I want the bootstrap col-* classes to behave like inline-blocks instead of floats.
When using the bootstrap grid, the vertical spaces and the most left & right are 15px but the spaces between the columns are double: 30px.
Is there a way to make them also 15px without changing Bootstrap CSS?
It's very easy to change the gutter without affecting the core bootstrap.css and still be able to use the same classes to push pull and offset.
Just make sure your .row around the new gutters has negative left and right margin equal to the padding on the left and right of the columns. Just like all floated elements this grid, like the Bootstrap grid, is exactly the same and will still require no more than 12 columns per row, if exceeded all heights need to be equal or you will need to clear them or use some other means such as jQuery or making them all the same height.
There is no vertical spacing on the grid, any vertical spacing comes from the children inside the column and it's usually the bottom margin value.
https://jsbin.com/wonuni/1/
CSS
.row.grid-15-gutter {
margin-left: -7.5px;
margin-right: -7.5px;
}
.row.grid-15-gutter [class*="col-"] {
padding-left: 7.5px;
padding-right: 7.5px;
}
.panel {
border: 1px solid red;
padding: 10px;
margin-bottom: 15px;
}
HTML
<div class="container">
<h2>Modified Grid</h2>
<div class="row grid-15-gutter">
<div class="col-sm-5">
<div class="panel">1</div>
</div>
<div class="col-sm-7">
<div class="panel">2</div>
</div>
</div>
<div class="row grid-15-gutter">
<div class="col-sm-5">
<div class="panel">1</div>
</div>
<div class="col-sm-7">
<div class="panel">3</div>
</div>
</div>
<hr>
<h2>Regular Grid</h2>
<div class="row">
<div class="col-sm-5">
<div class="panel">1</div>
</div>
<div class="col-sm-7">
<div class="panel">2</div>
</div>
</div>
<div class="row">
<div class="col-sm-5">
<div class="panel">1</div>
</div>
<div class="col-sm-7">
<div class="panel">3</div>
</div>
</div>
</div>
I have the following markup:
<div class="row-fluid">
<div class="span9"></div>
<div class="span3"></div>
</div>
+-----------------------+---------------+---+
| span9 contents here | span3 content | ->|-----space appearing here
+-----------------------+---------------+---+
How can I remove spacing of right side. I can't see padding and or margin value applied in but also space is appearing?
Update:
I found the reason why it was showing the space! I have added the following css
body, [class*="span"] {margin: 0 !important; padding: 0 !important;}
So, without removing this css can I remove the space?
Give your target div a class:
<div class="row-fluid target">
<div class="span9">Test1</div>
<div class="span3">Test2</div>
</div>
then you can add these css rules:
.target [class*="span"] {
margin-left: 20px !important;
}
.target [class*="span"]:first-child {
margin-left: 0 !important;
}
Bootply Demo
Try it:
<div class="row">
<div class="col-sm-4 col-xs-4 col-md-4">
<div class="span3"> </div>
</div>
<div class="col-sm-8 col-xs-8 col-md-8">
<div class="span9"></div>
</div>