bootstrap 2.3 fluid row spacing - css

I'm trying to create a row of divs (one per day of the week) that each contain a set of buttons for a user's availability for that time slot. However, no matter what I try I can't get the Bootstrap grid to space it evenly. Since there's seven days, I can't evenly divide the 12-space span, so each div is span1. However, in the Bootstrap docs they show this evenly filling the available space. In my example, it always crowds the divs to the left, so everything is cramped instead of taking up the available space.
I have a fiddle here: http://jsfiddle.net/usrwvreL/
Can someone point out the right way to use the grid / fluid row to space these items appropriately?

I find that an easy way to defeat the grid system when faced with this type of challenge is to take advantage of nested rows. Create three columns of size 4,
inside of which you could create three columns of four.
In the first parent column, you could have two child columns. The first child column would be offset using the .col-size-offset-4, which would then be proceeded by a .col-size-4.
The center parent column would have three child columns of size four, and the final parent column would have two child columns of size 4.
<!--This is the parent row-->
<div class="row">
<!--This is a parent column-->
<div class="col-md-4">
<!--Here is the gold. Create nested rows-->
<div class="row">
<!--Here we are offseting this column to produce a centered effect-->
<div class="col-md-offset-4">
</div>
<div class="col-md-4">
</div>
</div>
</div>
<!--The middle parent column-->
<div class="col-md-4">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
</div>
<div class="col-md-4">
</div>
</div>
</div>
<!--The last parent column, farthest to the right
<div class="col-md-4">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
</div>
<div class="col-md-4">
</div>
</div>
</div>
</div>

Bootstrap uses a 12 box grid system so if you need to divide by seven you could add a custom grid division,
so you can make a selector like .col-seventh{width: calc (100% / 7)}
to extend that you can make a new grid type:
.col-seventh-1{width: 14.285714%;}
.col-seventh-2{width: 28.571428%;}
.col-seventh-3{width: 42.857142%;}
.col-seventh-4{width: 57.142857%;}
.col-seventh-5{width: 71.428571%;}
.col-seventh-6{width: 85.714285%;}
.col-seventh-7{width: 100%;}
Instead you could also use flexboxes css3 property layout (non-bootstrap) to do all this for you!!

I am just wondering it might be a good solution to put the date on an individual line. So that you would just have to align a btn-group with 6 btns.

Why don't you try changing the layout. For say you can show three time buttons per row. The date will be on the top most row but it could be aligned center and the other buttons with time could be in the center as well.

Why can't you put like this?
<div class="container-fluid">
<div class="span1 avail-buttons"><span class="avail-date text-center">2015-02-11</span>
<div class="button-row row-fluid">
<button data-slot="0" type="button" class="avail-button btn btn-danger">08:45 AM</button>
<button data-slot="1" type="button" class="avail-button btn btn-danger">09:15 AM</button>
<button data-slot="2" type="button" class="avail-button btn btn-danger">09:45 AM</button>
<button data-slot="3" type="button" class="avail-button btn btn-danger">10:15 AM</button>
<button data-slot="4" type="button" class="avail-button btn btn-danger">10:45 AM</button>
<button data-slot="5" type="button" class="avail-button btn btn-danger">11:15 AM</button>
</div> </div></div>

Related

Two columns in two rows with Bootstrap

I am trying to learn Bootstrap grid more. I am trying to get two columns in two rows in the middle of my page.
So it should look like this:
Here is what I got so far:
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="col-xs-6 col-sm-6">
<div id="text1">
<label>Text 1</label>
</div>
<div id="text2">
<label>Text 2</label>
</div>
</div>
<div class="col-xs-6 col-sm-6">
<div id="text3">
<label>Text 3</label>
</div>
<div id="text4">
<label>Text 4</label>
</div>
</div>
</div>
</div>
But my elements are not in place where I want them.
Here is the solution in a fiddle: Solution 1
Now for the explanation of the problem:
First you need to set specific columns. Keep in mind that Bootstrap has a grid of 12. So your maximum can be 12 at all time. However, you don't need to have the columns fill the entire grid.
You can use something called offset which allows you to put empty space in your elements. Having the class class="col-md-5 col-lg-5 col-sm-5 offset-1" gives you a column with a value of 5 so you can actually position 2 columns and have space on the side.
I would suggest to go through the Bootstrap grid and play around in order to get a familiar feeling on how to manipulate it.
The style sheet margin-left:25px; margin-top:25px; gives you the space on the top and on the side of the columns themselves.

How can I reorder bootstrap columns on XS screens?

I have a simple bootstrap row with two columns:
<div class="row">
<div class="col-md-5 col-md-push-7">
This should show on right
</div>
<div class="col-md-7 col-md-pull-5">
This should show on left
</div>
</div>
I want the first row to show on the right and the second row on the left. All of this works, however when the screen size becomes small or extra small, the first column shows up first and second shows up second.
I would like to display second column first and first column second on small and extra small devices. I tried to achieve this with pull-right and pull-left classes but it did not work.
Would appreciate your suggestions.
P.S. I want the divs to stack
Something like this might work if you want the horizontal column ordering reversed:
<div class="row">
<div class="col-xs-5 col-sm-push-7">
This should show on right
</div>
<div class="col-xs-7 col-sm-pull-5">
This should show on left
</div>
</div>
Here is a JSFiddle demo.
If you do want these to stack rather than being side by side like the comments are talking about.
And if you want the second dive to show on top of the stack then you would do it something like this. Show and hide to swap between divs/blocks.
Here is a Fiddle I set the media breakpoints low at 320px.
<div class="row showhide1">
<div class="col-xs-5 col-xs-push-7 col-sm-5 col-sm-push-7 col-md-5 col-md-push-7 bg-primary">
This should show on right on larger views
</div>
<div class="col-xs-7 col-xs-pull-5 col-sm-7 col-sm-pull-5 col-md-7 col-md-pull-5 bg-info">
This should show on left on larger views
</div>
</div>
<div class="row showhide2">
<div class="col-xs-12 bg-primary">
Was on right, now on top on smaller views
</div>
<div class="col-xs-12 bg-info">
This should show on left on smaller views
</div>
</div>

Twitter Bootstrap panel height increases when resizing window

I'm having an issue where the height of one of my panels increases dramatically when I reduce the window size. Specifically, I have two panels in one row - one is col-grid-5 and the other is col-grid-4. The col-grid-4 header height (2nd one below AKA Recent Active Projects) is the one that is increasing way more than it should. Here's a plunkr:
http://plnkr.co/edit/NfI2xjth4ZU02duwLKDv
<div class="col-md-5">
<div class="panel">
....
</div>
</div>
<div class="col-md-4">
<div class="panel">
....
</div>
</div>
If you resize the window of the plunkr, you'll see it happen during a certain window width range. The problem goes away if I reorder the tables (i.e. put the 2nd one first). However, I can't figure out why that works.
Any tips would be great!
This is a float clearing issue. You need to include another .row tag around your nested .col-sm-6's. Simple answer is that any time you have a group of columns in bootstrap, you need a row around them.
<div class="col-md-5">
<div class="panel">
<div class="panel-heading no-border bg-primary">
<span class="text-lt">Time Summary</span>
</div>
<div class="row">
<div class="panel m-n col-sm-6 padder-v">
Hours Today
<i class="icon-arrow-right pull-right m-t-lg"></i>
<div class="h2 b-b m-t-sm">2.50 </div>
</div>
...
</div>
</div>
</div>
Updated plunker: http://plnkr.co/edit/rQqusAmUEWFrKMEqxRmz?p=preview

How do I align the button to the bottom of the row/column in bootstrap?

I have row with 4 columns each with a heading and some text. Most of the columns have a similar amount of text and push the button in their column down to match the rest of the columns. However one column has less text and doesn't push the button down far enough.
Is there a way to align the button to the bottom of the row? I would like to achieve this and keep it responsive at the same time so it looks like this when the screen is smaller:
This is my markup of the page just now:
<div class="container">
<div class="row">
<div class="col-md-3">
<h2>Heading</h2>
<p>text here</p>
<p><a class="btn btn-default" href="#" role="button">View details >></a></p>
</div>
<div class="col-md-3">
<h2>Heading</h2>
<p>text here</p>
<p><a class="btn btn-default" href="#" role="button">View details >></a></p>
</div>
<div class="col-md-3">
<h2>Heading</h2>
<p>less text here</p>
<p><a class="btn btn-default more" href="#" role="button">View details >></a></p>
</div>
<div class="col-md-3">
<h2>Heading</h2>
<p>text here</p>
<p><a class="btn btn-default" href="#" role="button">View details >></a></p>
</div>
</div>
</div>
There are several ways this can be done:
Give the containers a fixed height. This is not ideal as in order for it to look nice you will have to set different heights for each of the breakpoints.
You will also need to set the button to position: absolute, bottom: 0 and add some bottom padding/margin.
Use some javascript to match the heights using something like match height. You will also need to set the positions as in the previous point.
Add an additional row and repeat your buttons within 4 new cols. Then show or hide your original buttons and the new ones using bootstraps responsive classes.
set min-height equals to something to the text containing div for example
.col-md-3{min-height:300px;}
Set an explicit height on col-md-3.

Working with Bootstrap 3 classes but for only half of the page

I need two divs to sit side by side, and inside those divs will be divs that have bootstrap 3 classes. The problem is that when I restrict the left div, for example, to 50% by using col-xs-6, the col-xs-... classes on the child elements then only respond to their parent's width.
For clarity:
The purple divs' widths are based on a percentage of their parent, whereas I'd like them to be the same width as though they were a direct child of container whilst being able to keep them separate (and wrap them) from the other adjacent div (each div labelled col-xs-6 will be rendered from entirely different server-side controls).
NOTE: Ignore the fact I'm styling these for an XS display for now, this is only temporary while I work out the styles then I'll amend them accordingly.
For the three purple divs you would use col-xs-4
http://getbootstrap.com/css/#grid-nesting
The sum of the inner divs should add up to 12
You should add another row internally to create a new instance of your 12 columns. You might want to have a look at what Bootstrap calls Nesting Columns
<div class="container">
<div class="row">
<div class="col-xs-6 blue-back">
<div class="row">
<div class="col-xs-4 black-back">
</div>
<div class="col-xs-4 black-back odd">
</div>
<div class="col-xs-4 black-back">
</div>
</div>
</div>
<div class="col-xs-6 blue-back">
<div class="row">
<div class="col-xs-4 black-back">
</div>
<div class="col-xs-4 black-back odd">
</div>
<div class="col-xs-4 black-back">
</div>
</div>
</div>
</div>
</div>
try this JSFiddle

Resources