Center div when it takes 12 column in bootstrap - html

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>

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.

Two columns next to one other

I currently have two Divs next to each one big div like this:
The reason why I don't use a row instead of putting every div as a single one is that I need "DIV2" in the Mobile version to be between the two other divs.
But the big space between DIV1 and DIV3 ruins everything, how can i remove the spacing without losing my wanted layout?
HTML Code:
<div class="DIV1 col-xs-12 col-sm-8 col-md-8 col-lg-8" />
<div class="DIV2 col-xs-12 col-sm-4 col-md-4 col-lg-4" />
<div class="DIV3 col-xs-12 col-sm-8 col-md-8 col-lg-8" />
I use the standard Bootstrap code for the styling
What you can do is do is add float to your divs via the class pull-left or pull-right provided by bootstrap. This will make DIV3 take up the big space.
Check out the fiddle:
https://jsfiddle.net/80r028jq/1/
Both div1 and div3 should be in the same column so put these in a another div and than you can use display:inline-block or display:flex-box;
<div class="fl">
<div class="div1">
<div class="DIV1 col-xs-12 col-sm-8 col-md-8 col-lg-8" />
<div class="DIV3 col-xs-12 col-sm-8 col-md-8 col-lg-8" />
</div>
<div class="DIV2 col-xs-12 col-sm-4 col-md-4 col-lg-4" />
</div>
.fl
{
display:flex-box;
}

div increases height, and moves a div next to it in Bootstrap

I'm using Bootstrap right now and i'm having an issue.
This is my code:
<div id="calendario" class="col-xs-12 col-sm-4 col-md-3 col-lg-3">...</div>
<div id="seccion" class="col-xs-12 col-sm-8 col-md-9 col-lg-6">...</div>
<div id="fotos" class="col-xs-12 col-sm-4 col-md-3 col-lg-3">...</div>
<div id="secciondos" class="col-xs-12 col-sm-8 col-md-9 col-lg-6 col-lg-push-3">...</div>
My layouts look like this:
But when my calendar height is bigger, this is what happens:
What can I do to fix it?.
I have fixed it! :)
<div id="calendario" class="col-xs-12 col-sm-4 col-md-3 col-lg-3">
CALENDAR
</div>
<div id="seccion" class="col-xs-12 col-sm-8 col-md-9 col-lg-6">
SECTION 1
</div>
<div class="clearfix visible-sm-block"></div>
<div class="clearfix visible-md-block"></div>
<div id="fotos" class="col-xs-12 col-sm-4 col-md-3 col-lg-3">
PICTURES
</div>
<div class="clearfix visible-lg-block"></div>
<div id="secciondos" class="col-xs-12 col-sm-8 col-md-9 col-lg-6 col-lg-push-3">
SECTION 2
</div>
Just putting clearfix class where before the layout that is moved worked!
Thanks for the answers!!.
I can't vote up your comments because I don't have enough reputation :(.
Using containers and rows as the Bootstrap team intended, it's easy to keep things aligned:
<div class="container-fluid">
<div class="row">
<div id="calendario" class="col-xs-12 col-sm-4 col-md-3 col-lg-3">Calendar
<br>Calendar</div>
<div id="seccion" class="col-xs-12 col-sm-8 col-md-9 col-lg-6">Section One</div>
</div>
<div class="row">
<div id="fotos" class="col-xs-12 col-sm-4 col-md-3 col-lg-3">Section Two</div>
<div id="secciondos" class="col-xs-12 col-sm-8 col-md-9 col-lg-6 col-lg-push-3">Section Three</div>
</div>
</div>
Demo
You should use a wrapper around your calendar and make it .col-md-6 and then another around your second section and add the .col-md-6 class also. Like this, you would make sure that both your section will always talke half the screen. (You can also use other classes sm, xs and etc depeding on the layout you want to have)
For example:
<div class="col-md-6">
<div id="calendario" class="col-xs-12 col-sm-4 col-md-3 col-lg-3">...</div>
</div>
<div class="col-md-6">
<div id="seccion" class="col-xs-12 col-sm-8 col-md-9 col-lg-6">...</div>
</div>
This way, you'd have to review also for example your seccion and calendar, because now the whol col-md-6 will contains 12 columns also. Hope it helped. You might want to review the Grid system in there also:
http://getbootstrap.com/css/#grid

3 columns 2 rows responsive to 2 columns 3 rows

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).

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>