Bootstrap 3: How do you align column content to bottom of row - css

I have a row in Bootstrap 3 and 3 columns in that row. I want to align two of the columns to the bottom of the row and keep the first column at the top. When I use the traditional approach with position relative in the parent and absolute for both columns I get a weird behavior which I imagine is because of something in twitter bootstrap. Here's a bootply of what's happening:
http://www.bootply.com/125735
The absolute forces all the columns on top of eachother, can anyone help me out? The end result is to have something like so:
http://fahadalee.wordpress.com/2013/12/31/bootstrap-3-help-how-to-alin-div-in-bottom/
Thanks

You can use display: table-cell and vertical-align: bottom, on the 2 columns that you want to be aligned bottom, like so:
.bottom-column
{
float: none;
display: table-cell;
vertical-align: bottom;
}
Working example here.
Also, this might be a possible duplicate question.

Vertical align bottom and remove the float seems to work. I then had a margin issue, but the -2px keeps them from getting pushed down (and they still don't overlap)
.profile-header > div {
display: inline-block;
vertical-align: bottom;
float: none;
margin: -2px;
}
.profile-header {
margin-bottom:20px;
border:2px solid green;
display: table-cell;
}
.profile-pic {
height:300px;
border:2px solid red;
}
.profile-about {
border:2px solid blue;
}
.profile-about2 {
border:2px solid pink;
}
Example here: http://www.bootply.com/125740#

When working with bootsrap usually face three main problems:
How to place the content of the column to the bottom?
How to create a multi-row gallery of columns of equal height in one .row?
How to center columns horizontally if their total width is less than 12 and the remaining width is odd?
To solve first two problems download this small plugin https://github.com/codekipple/conformity
The third problem is solved here http://www.minimit.com/articles/solutions-tutorials/bootstrap-3-responsive-centered-columns
Common code
<style>
[class*=col-] {position: relative}
.row-conformity .to-bottom {position:absolute; bottom:0; left:0; right:0}
.row-centered {text-align:center}
.row-centered [class*=col-] {display:inline-block; float:none; text-align:left; margin-right:-4px; vertical-align:top}
</style>
<script src="assets/conformity/conformity.js"></script>
<script>
$(document).ready(function () {
$('.row-conformity > [class*=col-]').conformity();
$(window).on('resize', function() {
$('.row-conformity > [class*=col-]').conformity();
});
});
</script>
1. Aligning content of the column to the bottom
<div class="row row-conformity">
<div class="col-sm-3">
I<br>create<br>highest<br>column
</div>
<div class="col-sm-3">
<div class="to-bottom">
I am on the bottom
</div>
</div>
</div>
2. Gallery of columns of equal height
<div class="row row-conformity">
<div class="col-sm-4">We all have equal height</div>
<div class="col-sm-4">...</div>
<div class="col-sm-4">...</div>
<div class="col-sm-4">...</div>
<div class="col-sm-4">...</div>
<div class="col-sm-4">...</div>
</div>
3. Horizontal alignment of columns to the center (less than 12 col units)
<div class="row row-centered">
<div class="col-sm-3">...</div>
<div class="col-sm-4">...</div>
</div>
All classes can work together
<div class="row row-conformity row-centered">
...
</div>

I don't know why but for me the solution proposed by Marius Stanescu is breaking the specificity of col (a col-md-3 followed by a col-md-4 will take all of the twelve row)
I found another working solution :
.bottom-column
{
display: inline-block;
vertical-align: middle;
float: none;
}

Related

How can I achieve this CSS layout/grid

Hi, I was wondering how can I achieve a grid as shown above. Perhaps you guys have some tricks? :) I've tried Masonry, but I don't think it's fit for this.
I'm also using Bootstrap, but it doesn't have to be Bootstrap. Maybe if i'd had some keywords I could Google it, but I have nooo idea what exactly to search for.
This can be done easily using nested flexboxes- created a demo for you.
Adjust height and width of wrapper to suit your needs.
Enjoy!
* {
box-sizing: border-box;
}
.wrapper {
display: flex;
height: 250px;
}
div {
background: rgb(0, 140, 88);
}
.wrapper > div:first-child {
width: 50%;
}
.wrapper > div:last-child {
display: flex;
flex-direction: column;
width: 50%;
height: 100%;
}
.wrapper > div:last-child > div:first-child {
width: 100%;
height: 50%;
background: #2ba982;
}
.wrapper > div:last-child > div:last-child {
height: 50%;
display: flex;
}
.wrapper > div:last-child > div:last-child > div {
width: 50%;
height: 100%;
}
.wrapper > div:last-child > div:last-child > div:first-child {
background: #76c6ac;
}
.wrapper > div:last-child > div:last-child > div:last-child {
background: #bbe2d5;
}
<div class="wrapper">
<div></div>
<div>
<div></div>
<div>
<div></div>
<div></div>
</div>
</div>
</div>
Yes, you can do this with Bootstrap.
The major element will be one row with 2 div's (50% each, soo col-md-6 for example). The div on the right will have 2 row on his own, each with 50% of the height of his parent element. The second row of this will have 2 columns himself, with col-md-6 again. Don't forget each time you have a row or a container, you should always consider the 12 columns system again!
<div class="row">
<div class="col-md-6">
</div>
<div class="col-md-6">
<div class="row half-height">
<div class="col-md-12">
</div>
</div>
<div class="row half-height>
<div class="col-md-6">
</div>
<div class="col-md-6">
</div>
</div>
</div>
</div>
Not much time to do a jsfiddle, but I think it was clear
You would be looking at something similar to this (Note: This is just one of the many solutions available
Fiddle
What you do is you use the bootstraps grid system to create your shapes accordingly and you set the height of the left box (big box) to double the height of the smaller box
<div class="container">
<div class="row">
<div class="col-md-6" style="background-color:green;height:600px;">
</div>
<div class="col-md-6">
<div class="row">
<div class="col-md-12" style="background-color:blue;height:300px">
</div>
</div>
<div class="row">
<div class="col-md-6"style="background-color:yellow;height:300px"></div>
<div class="col-md-6"style="background-color:red;height:300px"></div>
</div>
</div>
</div>
</div>
As you can see in this code I have given the smaller voxes a height equal to half of the big box's height, the colors are just for visual representation and serve no function whatsoever, by using col-md-6 you can fit two columns in one row, which is what we need in your case, *Note, bootstrap has 12 columns* by using this we can safely assume that in the left box we need one div that's 12 columns wide in the first nested row (since we have two rows of smaller boxes we are using a nested row) and two boxes that are 6 columns wide in the second nested row.
Ofcourse in your case the inline style attributes will be moved to your style.css file
Hope this helps!

How to overlap columns in Bootstrap 3?

I'd like to create single row with two overlapping columns like that:
.row
.col-sm-7
.col-sm-6
so that 6th column of the grid is overlapped.
It's partially possible with a .col-sm-pull-1:
.row
.col-sm-6
.col-sm-6.col-sm-pull-1
but the 12th column becomes empty. I tried:
.row
.col-sm-6
.col-sm-7.col-sm-pull-1
but the second column moves to the next row.
I found the answer for Bootstrap 2 (How to overlap columns using twitter bootstrap?). Is it possible with the Bootstrap 3?
After seeing your image example, I think perhaps this is what you are looking for. (I made them overlap 2 columns because that will center it better)
.blue{
background-color: rgba(0,0,255,0.5);;
}
.row .red{
background-color: rgba(255,0,0,0.5);
position: absolute;
}
.red, .blue {
height: 70px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="red col-xs-7"></div>
<div class="blue col-xs-7 col-xs-push-5"></div>
</div>
</div>
Fiddle If you want to overlap the two columns in one row, you'll need negative margins. The bootstrap gutters/margins are layed out using positive and negative margins. I would recommend ids for the columns and then you can use z-index if you want one over the other one.
So change right margin on first and left margin on the second.
margin-right: -5%;
margin-left: -5%;
How the grid works is a great reference for how its built.
You need to place the new column under the same div as the one you want to overlap.
Here is an example
<style>
.first {
background-color: #dedef8;
border: solid black 1px;
}
.second {
background-color: #dedef8;
border: solid black 1px;
}
</style>
<body>
<div class="container">
<div class="row">
<div class="col-xs-7 first">
<p>This is the first column</p>
<div class="col-xs-6 second">
<p>This is the second </p>
</div>
</div>
</div>
</div>
</body>
Here's a jfiddle example: http://jsfiddle.net/NachoSupreme/o0fs78fv/

Having two columns taking the full width but with a separator

Hey I am having the following html code :
<div class='col-sm-7 foo'>...</div>
<div class='col-sm-5 foo'>...</div>
and in my css:
.foo {
background-color: white;
}
I can't add some margin between them as they are taking the full width due to bootstrap. Though I would like to add a separator between them (10px or so) with no background-color. How can I achieve this (I have to use bootstrap for other reasons).
You can edit the alignment of the col margins, and offset with padding:
Demo Fiddle
<div class='col-sm-7 foo'>...</div>
<div class='col-sm-5 foo'>...</div>
.foo {
background-color: white;
}
#media (min-width: 768px) {
.foo:first-of-type {
margin:0 5px 0 -5px;
padding-left:20px;
}
.foo:last-of-type {
margin:0 -5px 0 5px;
padding-right:20px;
}
}
body {
background:black;
}
Add another div width a col size of 1 and a width of 10px and no background. Change the column width of the others as needed.
Bootstrap columns have 15px padding by default, so could you wrap your foo class in a column? For example:
<div class="col-sm-7">
<div class="foo"></div>
</div>
<div class="col-sm-5">
<div class="foo"></div>
</div>
Then you have your foo divs with white background and 15px of padding (and no background color).
http://jsfiddle.net/3cz3zy3k/
Just put your background color on a child of the column rather than the column itself. In my experience it's best to avoid modifying grid elements in general.
.foo {
background-color: pink;
}
<div class="container-fluid">
<div class="row">
<div class='col-xs-7'><div class='foo'>...</div></div>
<div class='col-xs-5'><div class='foo'>...</div></div>
</div>
</div>
Demo

using overflow in css

How can i set the width of the first 2 divs to be dynamic (fit the contents width), while the 3rd div should use remaining horizontal space and be horizontally scrollable.
The result i need is that all 3 divs sit side by side and the 3rd div is hoziontally scrollable.
Script i have is as follows
HTML
<div id="a">
<table>
<tr><td>text</td></tr>
</table>
</div>
<div id="b">
<table>
<tr><td>text</td></tr>
</table>
</div>
<div id="c">
<table>
<tr><td>text</td></tr>
</table>
</div>
CSS
div#a
{
float: left;
}
div#b
{
float: left;
}
div#c
{
float: left;
width: 100%;
overflow-x: scroll;
}
The above script pushes div3 to the next line, which i dont want.
If you float #a and #b to the left, #c will fill the rest of the parent's width.
To get #c horizontally scrollable, you style its content container as:
#c .scroll-content {
/* You shouldn't do this on a table, but rather on a wrapping container. */
display: inline-block;
white-space: nowrap;
overflow: auto;
overflow-y: hidden;
}
I made an example at JSFiddle.
You should set a parent div to hold them all together in the same row. Something like this instead should work.
<div id="parent">
<div id="a">
<table>
<tr><td>text</td></tr>
</table>
</div>
<div id="b">
<table>
<tr><td>text</td></tr>
</table>
</div>
<div id="c">
<table>
<tr><td>text</td></tr>
</table>
</div>
</div>
div#a
{
float: left;
}
div#b
{
float: left;
}
div#c
{
float: left;
}
#parent{
width: 100%;
overflow-x: scroll;
}
Also you might want to refactor your code. Since all of the divs are floating left, you might want to use just one class that floats to the left. I hope this helps.
The CSS...
#a {
float:left;
border:solid 1px #000;
width:33%;
}
#b {
float:left;
border:solid 1px #000;
width:33%;
}
#c {
float:left;
border:solid 1px #000;
width:33%;
}
.scroll{
float:left;
overflow:auto;
width:100%;
}
.content {
width:1000px;
overflow:auto;
}
And the HTML...
<div id="a">
This is text within my first content box
</div>
<div id="b">
This is text within my second content box
</div>
<div id="c">
<div class="scroll-content">
This is text within my third content box and this is horizontal and scrollable
</div>
</div>
UPDATED JSFIDDLE LINK BELOW AGAIN!!!
And a demo on jsfiddle - http://jsfiddle.net/GeLqV/1/
Mark, this will work for you now. I now see that you wanted all three divs on the same row, and the last one being able to horizontally scroll. Look at my jsfiddle demo. No matter what your screen size will be, all three div's are fluid in size and will stay together (for the most part).

CSS layout on HTML5

I am developing one web application in HTML5 and js. And I am using some 'Canvas' tags in it. So I would like to structure them on the screen like:
I have achieved it by using such CSS tags as: margin-right, margin-left, top, position.
The problem is when I use these css tags, then I am more or less adapting the whole layout to one screen only, unfortunately my aim is to support any screen possible.
Maybe there are professionals in layouting who could help with this particular problem.
P.S. When window size is changed, canvases should not be resized
Maybe its a good idea to use a css framework like twitter bootstrap.
Its build up for different screen sizes and crossbrowser. It also offers a responsive design.
Have a look at the gridsystem.
About one canvas inside another:
<div class="row">
<div class="span4">
<div class="row">
<div class="span4">..</div>
<div class="span4">.. </div>
<div class="span4">..</div>
</div>
<div class="span8">...</div>
</div>
You can do "unlimited" nesting of columns, see 'Nesting columns' in documentation linked above.
I have created you a demo.
I believe this is what you want.
HTML:
<div id="wrapper">
<div id="col1">
<div class="canvas">Canvas-Left-1
<div class="innercanvas">Canvas-Left-1-1</div>
</div>
<div class="canvas">Canvas-Left-2
<div class="innercanvas">Canvas-Left-2-1</div>
</div>
</div>
<div id="col2">Canvas 0</div>
<div id="col3">
<div class="canvas">Canvas-Rigt-1
<div class="innercanvas">Canvas-Right-1-1</div>
</div>
<div class="canvas">Canvas-Right-2
<div class="innercanvas">Canvas-Right-1-1</div>
</div>
</div>
</div>​
CSS
* {margin: 0; padding: 0;}
#wrapper {display: block; margin: 0 auto; width: 1000px; background-color: green; overflow: auto;}
#col1 {display: inline-block; width:200px; background-color: gray; position: relative; float: left;}
#col2 {display: inline-block; width:600px; background-color: yellow; position: relative; float: left;}
#col3 {display: inline-block; width:200px; background-color: blue; position: relative; float: left;}
.canvas {background-color: black; margin: 10px; color: white}
.innercanvas {background-color: purple; margin: 10px; color: white}​
Boris you would need to either implement it using outside containers for each area (ie. 3 outer-divs, one for each column, and one "main" div to position to in the middle of the screen, using percentages and max/min width to control the desired output).
Or save yourself some trouble and use a fluid grid system like those:
http://cssgrid.net/
http://www.designinfluences.com/fluid960gs/
You may want to take a look here too, there is some neat information on fluid layouts.

Resources