3 columns 2 rows responsive to 2 columns 3 rows - html

I'm using Bootstrap css grid layout it works great.
I haven't found an example where it can be responsive and convert 3 columns and 2 rows into 2 columns and 3 rows.
What it does is create single column of 6 rows. I can convert even columns from 4 to 2 but how to do 3 as they are in 2 different rows?
I thought if there is solution for an even number of columns then it could be done for odd.

Try using
<div class="col-xs-6 col-sm-6 col-md-4" ></div>
<div class="col-xs-6 col-sm-6 col-md-4" ></div>
<div class="col-xs-6 col-sm-6 col-md-4" ></div>
<div class="col-xs-6 col-sm-6 col-md-4" ></div>
<div class="col-xs-6 col-sm-6 col-md-4" ></div>
<div class="col-xs-6 col-sm-6 col-md-4" ></div>

Take into consideration that you may have to think outside of the box (punny I know) on this one. It may help visualize it better if you drew out the different stages first.
Then consider you may not need rows, except the one to contain the columns. In Bootstrap extra columns will force a second or third row automatically.
http://getbootstrap.com/css/#grid-example-mixed
You have 6 total divs. Then just adjust the column class width numbers.
Now you didn't say if you wanted the three columns on a desktop-sized screen or a mobile. I'm going to assume here, for the sake of simplicity, that the 2 columns layout is a mobile layout.
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-4"> Content </div>
<div class="col-xs-6 col-sm-6 col-md-4"> Content </div>
<div class="col-xs-6 col-sm-6 col-md-4"> Content </div>
<div class="col-xs-6 col-sm-6 col-md-4"> Content </div>
<div class="col-xs-6 col-sm-6 col-md-4"> Content </div>
<div class="col-xs-6 col-sm-6 col-md-4"> Content </div>
</div>
You CAN switch it up, but why put that many columns into such a small space... there could be reasons to do it that way but it's not common due to finger-width issues. However, Bootstrap is that level of flexible.
<div class="row">
<div class="col-xs-4 col-sm-4 col-md-6"> Content </div>
<div class="col-xs-4 col-sm-4 col-md-6"> Content </div>
<div class="col-xs-4 col-sm-4 col-md-6"> Content </div>
<div class="col-xs-4 col-sm-4 col-md-6"> Content </div>
<div class="col-xs-4 col-sm-4 col-md-6"> Content </div>
<div class="col-xs-4 col-sm-4 col-md-6"> Content </div>
</div>
Edit
There are also ways to keep it centered using offsets, if you have say a 7 column layout. It just requires adjusting the width of the columns and then adding offsets to keep it centered.
http://getbootstrap.com/css/#grid-offsetting
An important thing to remember when adding an offset, is that the col width plus the offset cannot equal 12 or it will be pushed all the way to the right. It also works best when the column width is an even number (2, 4, 6, 8, or 10).
You can practice in JSfiddle or CodePen (codepen live updates in a WYSIWYG viewer).

Related

Trying to understand how to use Bootstrap Row/Columns?

I am trying to make it so on a large screen there are 4 columns, a medium screen there are 2 and on an extra small screen just 1. The large and extra small work, but I'm assuming the medium does not simply because col-6 4 times would make it 24 instead of 12 columns. Here is my code:
<div class="row">
<div class="col-xs-12 col-med-6 col-lg-3">
<img src="http://www.martinezcreativegroup.com/wp-content/uploads/2014/05/img-placeholder.png">
</div>
<div class="col-xs-12 col-med-6 col-lg-3">
<img src="http://www.martinezcreativegroup.com/wp-content/uploads/2014/05/img-placeholder.png">
</div>
<div class="col-xs-12 col-med-6 col-lg-3">
<img src="http://www.martinezcreativegroup.com/wp-content/uploads/2014/05/img-placeholder.png">
</div>
<div class="col-xs-12 col-med-6 col-lg-3">
<img src="http://www.martinezcreativegroup.com/wp-content/uploads/2014/05/img-placeholder.png">
</div>
</div>
How would I be able to make this work so that the medium column only has 2 columns?
You've used wrong class for medium screen size. It should be col-md-6 instead of col-med-6
And if you declare 4 columns of col-md-6, it will rearrange the columns such that the first two (total of 12) will occupy the first row and the next two will be arranged in the second row.
Your approach is correct, you only got the medium column classname wrong, it should be: col-md-6. (Bootstrap docs)
Here you go with a solution https://jsfiddle.net/8er0e3Lh/1/
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4">
<img src="http://via.placeholder.com/350x15">
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4">
<img src="http://via.placeholder.com/350x15">
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4">
<img src="http://via.placeholder.com/350x15">
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4">
<img src="http://via.placeholder.com/350x15">
</div>
</div>
</div>
Order of class should be from lower screen to larger screen.
Hope this will help you.
It is col-md-6 not col-med-6. Please fix this class name, then it will work.

Bootstrap: stack rows of divs

Is there a way to stack a various number of divs in multiple rows when theres not enough space to show them in a single row?
So what I mean is, imagine you have 20 divs but only 5 fit in the first row. Then there should be 4 rows with 5 items.
On the other hand when we only have 3 items then there should only be one row with 3 items.
Flexbox makes this easy. Have a look here.
The Bootstrap has 12 columns per rows. You can nest columns/rows but not recommend that you nest containers.
With that being said, you can have up to 12 columns per row. To control how it is 'stacked' you classify which type of columns it belongs to. See the demo.
https://codepen.io/pkshreeman/pen/LLYZqm
Resize the window, and you will see what it does for different settings.
Hope this helps.
This is the code used in demo:
<div class="container">
<div class="row">
<div class="col-md-6"> col-md-6 </div>
<div class="col-md-6"> col-md-6 </div>
</div>
<div class="row">
<div class="col-md-6 col-sm-6"> col-md-6 col-sm-6 </div>
<div class="col-md-6 col-sm-6"> col-md-6 col-sm-6 </div>
</div>
<div class="row">
<div class="col-md-6 col-sm-2"> col-md-6 col-sm-2 </div>
<div class="col-md-6 col-sm-2"> col-md-6 col-sm-2 </div>
</div>
<div class="row">
<div class="col-md-4 col-sm-6">col-md-4 col-sm-6
</div>
<div class="col-md-4 col-sm-6">col-md-4 col-sm-6
</div>
<div class="col-md-4 col-sm-6">col-md-4 col-sm-6
</div>
</div>
<div class="row">
<div class="col-md-4 col-sm-2">col-md-4 col-sm-2
</div>
<div class="col-md-4 col-sm-2">col-md-4 col-sm-2
</div>
<div class="col-md-4 col-sm-2">col-md-4 col-sm-2
</div>
</div>
</div>

Center div when it takes 12 column in bootstrap

I have an element in Bootstrap row. The element takes different amount of columns on xs, sm, md and lg configurations of a screen. I need the element to be in the middle when it takes 12 columns. Is it possible? If so how can I do that?
For example:
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4">
SOME TEXT
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4">
SOME TEXT
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4">
SOME TEXT
</div>
And if I put the row into a div which is fluid I want elements always be in the middle, but when I shrink browser to sm configuration it makes an element take 12 columns by itself and hence I have relatively to the gap on left side huge gap on right.
Oh! There I came out with the idea and it seems to work out. I just add a bit of css to a elements which take columns:
margin:0 auto;
and what the code does is actually centers the elements in their columns.
Yes, #GaneshRadhakrishnan is right, you should use bootstrap's center-text class like this:
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4 center-text">
SOME TEXT
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4 center-text">
SOME TEXT
</div>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-4 center-text">
SOME TEXT
</div>
</div>

Responsive Mobile and Desktop Friendly 4 Column Footer w Custom Margins w Bootstrap Grids

I'd like to create a 4 column footer that looks nice. The content for the footers varies in width and I would like to have an equal amount of space between each block of text in the columns. The only way I know to do this is to add a class to each div and play with the margins until things look right. I seem to have to add a negative margin to one or more columns so that the spacing is equal between each block of text. I can get things to look good on large screens, but then when you view the page in a smaller screen, divs overlap and things get wonky. I'd like the columns to start stacking on top of each other and filling up the entire width of the screen as much as possible. Here's a jsfiddle and my code that shows what I'm trying to do. What would you add to this to make it look good on desktops and as many mobile devices as possible?
http://jsfiddle.net/natetg/qhtyL7t8/
'<div class="navbar navbar-fixed-bottom footer">
<div class="container">
<div class="row">
<div class="col-xs-6 col-md-4 col-lg-3">
<p>columnContentWithLargeWidth</p>
</div>
<div class="col-xs-6 col-md-4 col-lg-3">
<p>columnContentShort</p>
</div>
<div class="col-xs-6 col-md-4 col-lg-3">
<p>columnShort</p>
</div>
<div class="col-xs-6 col-md-4 col-lg-3">
<p>ColumnContentWithLargestWidthAndWantThisAllOnOneLinePlease</p>
</div>
</div>
</div>
</div>`
Try using .container-fluid and .row-fluid instead of container and row.
<div class="navbar navbar-fixed-bottom footer">
<div class="container-fluid">
<div class="row-fluid">
<div class="col-xs-6 col-md-4 col-lg-3">
<p>columnContentWithLargeWidth</p>
</div>
<div class="col-xs-6 col-md-4 col-lg-3">
<p>columnContentShort</p>
</div>
<div class="col-xs-6 col-md-4 col-lg-3">
<p>columnShort</p>
</div>
<div class="col-xs-6 col-md-4 col-lg-3">
<p>ColumnContentWithLargestWidthAndWantThisAllOnOneLinePlease</p>
</div>
</div>
</div>
</div>

Grouping bootstrap column with a div

In bootstrap, I need to keep the proportion of the following columns, yet I need to group 2 columns with a div so that I can modify the background.
<div class="col-xs-6 col-md-3"></div>
<div class="col-xs-6 col-md-3"></div>
<div class="col-xs-6 col-md-6"></div>
I am trying to do something like:
<div class="col-xs-6 col-md-3"></div>
<div class="grey">
<div class="col-xs-6 col-md-3"></div>
<div class="col-xs-6 col-md-6"></div>
</div>
But it changes the proportion, as it is considering grey div as 18 grid.
col-*-4 will give you 3 columns of equal width (spanning 4 cols each). No need to group them to modify their background color. Just apply the same class with background color defined in your css:
<div class="col-xs-4">Col 1</div>
<div class="col-xs-4 grey">Col 2</div>
<div class="col-xs-4 grey">Col 3</div>
css
.grey{backround:grey;}
Demo: http://www.bootply.com/E78M9vm9Uk
My personal advise will be this. Though I'm really certain of what your goal is. Since bootstrap has an 12 wide grid your col-xs-6 will put 2 columns beside each other and the next one below.
<div class="col-xs-6 col-md-3"></div>
<div class="col-xs-6 col-md-3 grey"></div>
<div class="col-xs-6 col-md-6 grey"></div>
If you really looking for grouping I should consider this approach:
<div class="col-xs-6 col-md-3"></div>
<div class="grey col-md-9">
<div class="col-xs-6 col-md-4"></div>
<div class="col-xs-6 col-md-8"></div>
</div>
But that will not correspond when he enters xs. Since it is not clear to me what you want with that size.