Margins between columns - css

So the new Bootstrap v3 code looks like this:
<div class="row">
<div class="col-md-4 bg-red">
<h2>Heading</h2>
<p>My text here...</p>
</div>
<div class="col-md-4 bg-green">
<h2>Heading</h2>
<p>My text here...</p>
</div>
<div class="col-md-4 bg-blue">
<h2>Heading</h2>
<p>My text here...</p>
</div>
</div>
Because Bootstrap 3 has removed column margins (now has padding left and right). How can I put a background color on the class="col-lg-4" div and have the page background gap between each div?
Note: it must be a background color on the class="col-lg-4" div.

One way is to use the background-clip property with the content-box value so that the painting area is clipped to the content box of .col-lg-4 instead of the border box like it is by default.

Use .col-*-3 and add margin to it. You have 4 columns but the 4th is unused and then you have room for the margins. Here's an example:
http://www.bootply.com/R9iSDcNuzY
HTML
<div class="row">
<div class="col-md-3 bg-danger col-margin">
<h2>Heading</h2>
<p>My text here...</p>
</div>
<div class="col-md-3 bg-success col-margin">
<h2>Heading</h2>
<p>My text here...</p>
</div>
<div class="col-md-3 bg-primary col-margin">
<h2>Heading</h2>
<p>My text here...</p>
</div>
</div>
CSS
/* CSS used here will be applied after bootstrap.css */
.col-margin{
margin: 10px;
}

Related

Vertical align centre and matching heights in Bootstrap

I'm trying to do some vertical aligning in Bootstrap and can't seem to achieve it with the various flex box classes (align-items-center etc).
I need the text content in the boxes of the below codepen to be vertically centered ... whilst also each box should match the height of the tallest box (as is currently working)... can anyone help?!
The inner divs need to be wrapped in a link - don't know if thats affecting things?
https://codepen.io/jwacreative/pen/VwjePEj
<div class="container">
<div class="row">
<div class="col-md-6 col-lg-4 mb-4">
<a href="http://">
<div class="summary-box h-100" style="background:red">
<h2>Title</h2>
<p>Some text</p>
</div>
</a>
</div>
<div class="col-md-6 col-lg-4 mb-4">
<a href="http://">
<div class="summary-box h-100" style="background:green">
<h2>Title</h2>
<p>Some text longer text Some text longer text Some text longer text Some text longer text Some text longer text Some text longer text<< /p>
</div>
</a>
</div>
<div class="col-md-6 col-lg-4 mb-4">
<div class="summary-box h-100" style="background:blue">
<h2>Title</h2>
<p>Some text</p>
</div>
</div>
</div>
CSS Grid should be able to help with this...
.summary-box {
display: grid;
align-content: center;
}

Bootstrap 3 panels with text and images (with different background for the images)

I am trying to implement 3 panels with text and images with a different background color for the images (darker) and another color for the text.
this is my current code which works for the desktop version of the website but breaks on mobile.
At the moment the layout is IMAGE->IMAGE->IMAGE. Text->Text->Text and it should be IMAGE -> Text. Image -> Text. Image -> Text:
current code
So as per my comment, you need to include both your image and text into a column, then all three columns into a row. Something like this:
<div class="row">
<div class="col-md-4">
<div><img src="#"></div>
<div>Some text</div>
</div>
<div class="col-md-4">
<div><img src="#"></div>
<div>Some text</div>
</div>
<div class="col-md-4">
<div><img src="#"></div>
<div>Some text</div>
</div>
</div>
You should check out the bootstrap site for guidance on using their grid layout :)
In bootstarp to using panels you must use panel codes
you can see the bootstrap panels here Bootstrap Panels
<div class="row">
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">Panel heading without title</div>
<div class="panel-body">
<img src="#">
<p>text Here</p>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Panel heading without title</div>
<div class="panel-body">
<img src="#">
<p>text Here</p>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Panel heading without title</div>
<div class="panel-body">
<img src="#">
<p>text Here</p>
</div>
</div>
</div>
</div>
Automatically all three columns put in the one row if you want use different column grid you must the another div tag to specify the grids
also panels have the panel title class but I used panel heading class you can use panel title if you want

How to make text not to overflow box in bootstrap

i am using Bootstrap 3, and i have a text within a col and when it's longer, it does not fit the div and overflows it in the width of the box. I have used different display styles, do a lot of search but without success.
<div class="container-fluid">
<div class="row">
<div class="col-lg-10 col-md-10 col-sm-12 col-xs-12 col-lg-offset-1 col-md-offset-2">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="thumbnail">
<img src="http://www.kungfunguyen.com/wp-content/uploads/2013/08/Bootstrap-2-1-Is-the-Latest-Update-to-Twitter-s-Popular-Open-Source-Project.png">
<div class="caption">
Very long text which oveflows the whole div in width.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
</div>
</div>
</div>
</div>
</div>
</div>
Example with thumbnail and caption, the same problem
http://jsfiddle.net/zqeLse5q/
Thanks
.caption{
word-wrap: break-word;
}
http://jsfiddle.net/zqeLse5q/2/

Add gap between two Divs

I have a screen split in two, using two columns.
<div class="row">
<div class="col-md-6 well">
Left Box
</div>
<div class="col-md-6 well">
Right
</div>
</div>
I need a small (approx 10px) gap between the two columns.
http://www.bootply.com/vaOb1WdR5I
Can this be done?
Both boxes would need to reduce by 5 pix (in the above example), as I need the total width to remain.
Edit: Some ideas nearly work, but I am getting an extra Well that I don't want. With this:
<div class="row">
<div class="col-md-6">
#Html.Action("ShowDuePayments", "Transaction")
</div>
<div class="col-md-6">
#Html.Action("ShowRecentTransactions", "Transaction")
</div>
</div>
I get this:
The 'under' well div shouldn't be visible.
A couple of points:
You shouldn't add extra classes to the Bootstrap columns (that's not a hard and fast rule, but a good recommendation)
You are missing the container wrap.
Make changes using those rules and it looks like this:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="row">
<div class="col-md-12">
<div class="well">Left Top Box</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="well">Left Bottom Box</div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="well">Right Box</div>
</div>
</div>
</div>
How about this?
<div class="row">
<div class="col-md-6" style='padding-right:5px'>
<div class='well'>
Left Box
</div>
</div>
<div class="col-md-6" style='padding-left:5px'>
<div class='well'>
Right
</div>
</div>
</div>
http://www.bootply.com/Ogrte6IQzw
If you remove the inline styling, you will have the natural spacing provided by bootstrap, which is 15px padding.
You can change the class of col-md-6 and add width:49%, and to the 2nd div add pull-right class like:
HTML:
<div class="row">
<div class="col-md-6 well">
Left Box
</div>
<div class="col-md-6 well pull-right">
Right
</div>
</div>
CSS:
.col-md-6{
width:49%;
}
You can also try to add padding to the two div tags ie:
.col-md-6{
padding:5px;
}
This would add a bit of padding to all the sides - unless you use padding-left & padding-right and assign different class names to the divs - depending on how you want your code to be layed out.
You could also use an additional class so you only modify special column-6 elements and not all on your site. This example also uses percentage based widths as Flopet17s. You could tweak the percentage number to better fit your desired gap width.
.withgap {
width: 49%;
margin-right:1%;
}
<div class="row">
<div class="col-md-6 well withgap">
Left Box
</div>
<div class="col-md-6 well">
Right
</div>
</div>

Vertical alignment within Bootstrap grid

It seems like a simple question, but I simply can't find an answer.
This fiddle should be fairly straightforward:
http://fiddle.jshell.net/52VtD/4040/
<div class="panel panel-default entete" >
<div class="row">
<div class="col-md-6">
<div class="title">
to be centered vertically
</div>
</div>
<div class="col-md-2">
<p>Text</p>
<p>Text</p>
<p>Text</p>
</div>
<div class="col-md-2">
Text
</div>
<div class="col-md-2">
Text
</div>
</div>
</div>
I'm trying to align vertically the contents of the first column relatively to the others.
If the window is resized (and there is no column to its right), the first column should be as high as its content (cannot use a fixed height).
The correct way to do this using Bootstrap 4 Grid is by using one of then align-items-... classes on the .row element, or align-self-... on the .col elements.
In the case of the OP's original request, the best implementation would be
<div class="col-md-6 align-self-center">
<div class="title">
to be centered vertically
</div>
</div>
If you wanted to, for example, set all of the .col elements to be aligned to the bottom vertically, you would set align-items-end on the .row element like so:
<div class="row align-items-end">
Source: https://getbootstrap.com/docs/4.0/layout/grid/#vertical-alignment
Check out this http://fiddle.jshell.net/52VtD/4043/
<div class="panel panel-default entete" >
<div class="row" style="display:table">
<div class="col-md-6" >
<div class="title" style="display:cell;vertical-align:middle">
to be centered vertically
</div>
</div>
<div class="col-md-2">
<p>Text</p>
<p>Text</p>
<p>Text</p>
</div>
<div class="col-md-2">
Text
</div>
<div class="col-md-2">
Text
</div>
</div>
</div>
http://fiddle.jshell.net/8uzn7fou/2/
HTML:
<div class="panel panel-default entete" >
<div class="row" >
<div class="col-md-6 title_div" >
<div class="title" >
to be centered vertically<br/> to be centered vertically
</div>
</div>
<div class="col-md-2">
<p>Text</p>
<p>Text</p>
<p>Text</p>
</div>
<div class="col-md-2">
Text 2
</div>
<div class="col-md-2">
Text 3
</div>
</div>
</div>
CSS:
.title_div{
display: table;
}
.title{
height:100%; display: table-cell!important;
vertical-align: middle;
}
JQ:
function setHeight()
{
var max=0;
$('.entete .col-md-2').each(function(){
var h=$(this).height();
if(h>max) max=h;
})
$('.title_div').height(max);
}
setHeight()
Note: In function setHeight () should be added to check the width of the window in order not executed for smaller screens

Resources