bootstrap mobile first layout issue - html

Please check my demo .I have been trying to implement this please hover above any plan block with different grid size i have some how managed to make it work all the grid sizes except col-xg(<768px).Here on hover the div breaks and shows irregular behavior.Below i have added the sample how i want block to render <768px grid and on hover block has to change to blackish color
This is the Second Issue uneven height
I am trying to build a page from the scratch and so please be kind enough to point out my mistakes
FIDDLE
HTML
<div id="Container_Plans">
<div class="rows">
<div class="col-lg-2 col-md-2 col-sm-2 ">
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 ">
<div class="products_Container">
<div class="Product_Plan">
<span class="PlanName">
#01
</span>
</div>
<div class="Product_Feature">
<span class="Feature_Content">
<h2>Compact Plan</h2>
<p><span class="break">DDNS Feature for </span>remote viewing </p>
<div>
# RS 10000 /-
</div>
free Dns Subscription for a year
</span>
</div>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="products_Container">
<div class="Product_Plan">
<span class="PlanName">
#02
</span>
</div>
<div class="Product_Feature">
<span class="Feature_Content">
<h2>Regular Plan</h2>
<p><span class="break">DDNS Feature for </span>remote viewing </p>
<div>
# RS 21000 /-
</div>
free Dns Subscription for a year
</span>
</div>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 ">
<div class="products_Container">
<div class="Product_Plan">
<span class="PlanName">
#03
</span>
</div>
<div class="Product_Feature">
<span class="Feature_Content">
<h2>Performance Plan</h2>
<p><span class="break">DDNS Feature for </span>remote viewing </p>
<div>
# RS 45000 /-
</div>
free Dns Subscription for a year
</span>
</div>
</div>
</div>
<div class="col-lg-1 col-md-1 col-sm-1">
</div>
</div>
</div>

It looks like the background changes are being determined on an on-hover css rule for .products_Container. Try setting the rule for its parent, col-lg-3 col-md-3 col-sm-3 col-xs-12, and give the parent the desired on-hover background color.
Does this achieve what you are attempting to accomplishing?
http://jsfiddle.net/sYJKE/2/embedded/result/

You need a clearfix on the products_Containers. The floated elements inside aren't filling their container element, which the clearfix will take care of. Here's Nicolas Gallagher's lovely clearfix (http://nicolasgallagher.com/micro-clearfix-hack/):
.products_Container:before,
.products_Container:after {
content: " "; /* 1 */
display: table; /* 2 */
}
.products_Container:after {
clear: both;
}
/**
* For IE 6/7 only
* Include this rule to trigger hasLayout and contain floats.
*/
.products_Container {
*zoom: 1;
}
http://jsfiddle.net/EG7v9/2/
Regarding the height difference, the fast and dirty way to fix that is the make the h2 tags the same height no matter what. You can drop a break <br> inside the h2 to split the plan type and the word plan onto two lines:
<h2>Regular <br>Plan</h2>
Just do that for each of the plan h2s.

Related

Bootstrap 3 stretch elements in row to same size [duplicate]

I have a row of thumbnails like this:
I want them to be equal height though. This is my code:
<div class="row text-center">
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<div class="caption">
<h3>HOTKEY + COMBO</h3>
<p>Hotkey description goes here. Category only shown in explore.</p>
<p>
<a href="#" class="btn btn-default" data-tooltip="Change Hotkey">
</p>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="thumbnail">
<div class="caption">
<h3>HOTKEY + COMBO</h3>
<p>short desc</p>
<p>
<a href="#" class="btn btn-default" data-tooltip="Change Hotkey">
</p>
</div>
</div>
</div>
<div class="col-md-3 col-sm-6 hotkey-add">
<div class="thumbnail">
<div class="caption">
<p></p>
<p><span class="glyphicon glyphicon-plus"></span></p>
</div>
</div>
</div>
</div>
Is this possible? Like we see in bootstrap4 here is equal height cards:
http://www.codeply.com/render/KrUO8QpyXP#
I know I'm a little late on this, but I think the best way is flexbox. Here's how it would work in Bootstrap 3:
.row.display-flex {
display: flex;
flex-wrap: wrap;
}
.thumbnail {
height: 100%;
}
Just add display-flex to the containing row. Also, the upcoming Bootstrap 4 has flexbox as the default so this extra CSS won't be necessary in the future.
Thumbnails with flexbox
You can also do more with the position of child elements.
Also see,
make Bootstrap columns all the same height
It seems that bootstrap 4, like you show in the example, is using to get the same height, display: table for the container div and display: table-cell for the inner ones.
Other solution can be using <table> instead <div>, using flex property...
Checkout this How can I make Bootstrap columns all the same height?

Element exceeds column its in from Bootstrap

So i'm trying to make a bootstrap row with a title and a badge to the right.
To see what's happening see the image at the bottom of this post.
The code is as follows:
<div class="box workoutscontent">
<div class="row">
<div class="col-xs-10 col-md-10">
<h1 class="workouttitle">#workout.WorkoutTitle</h1>
</div>
<div class="col-xs-2 col-md-2">
<h1>
#if (workout.Goal == "Afslanken")
{<span class="label label-primary workoutlabel">Afslanken</span>}
#if (workout.Goal == "Aankomen")
{<span class="label label-success workoutlabel">Aankomen</span>}
#if (workout.Goal == "Spiermassa opbouwen")
{<span class="label label-warning">Spiermassa opbouwen</span>}
</h1>
</div>
</div>
<hr/>
<div class="row">
<div class="col-md-12">
<p>#workout.DescriptionShort</p>
</div>
</div>
</div>
The css applied to it is
Title:
.workoutscontent h1 {
margin-top: 0;
font-family: 'Nunito', sans-serif;
}
Label:
.workoutlabel {
float: right;
}
The result looks like this:
Why does the label go outside of the box I put it in?
The main problem you're facing is that the right column definition is not large enough for it's content, so you need to take some away from the left column and add to the right. Remember to shoot for 12 columns per row.
Also you don't need the float on the h1, just use Bootstrap's text-right class on the div, to align in right in the column. Using a grid can help you eliminate using floats which can create extra styling work for you as it takes the elements out of the normal flow.
Below is an example showing your markup as is (structurally) and another version below it with a different column set up allowing room for the right hand column's content, as well as removing the float. I've put a grey background on the columns so you can see what's happening there.
In the column settings I changed it to:
XS Screens: 5/7
S Screens: 6/6
M+ Screens: 7/5
.workoutscontent h1 {
margin-top: 0;
font-family: 'Nunito', sans-serif;
}
.workoutlabel {
float: right;
}
/* for demonstration purposes only */
div.row div {
background: #cccccc;
border: 1px solid white;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<code>Unmodified:</code>
<div class="box workoutscontent">
<div class="row">
<div class="col-xs-10 col-md-10">
<h1 class="workouttitle">Title</h1>
</div>
<div class="col-xs-2 col-md-2">
<h1>
<span class="label label-primary workoutlabel">Afslanken</span>
</h1>
</div>
</div>
</div>
<hr/>
<code>Fixed:</code>
<div class="box workoutscontent">
<div class="row">
<div class="col-xs-5 col-s-6 col-md-7">
<h1 class="workouttitle">Title</h1>
</div>
<div class="col-xs-7 col-s-6 col-md-5 text-right">
<h1>
<span class="label label-primary">Afslanken</span>
</h1>
</div>
</div>
</div>
BTW... <span> is perfectly acceptable markup within an h1 as it is an inline element, so don't worry about that despite comments saying otherwise. Bootstraps own documentation shows it done this way: https://getbootstrap.com/docs/3.3/components/#labels
instead of float:right on .workoutlabel class just simply add text-right class on
also replace col-xs-10 col-md-10 with col-xs-9 col-md-9 and col-2-xs col-2-md to col-xs-3 col-md-3

Center elements in a grid row

i have the following:
"
<div class="container">
<div class="row">
<div class="col-md-3">
<h3><span class="label label-default">Current Job</span></h3>
</div>
<div class="col-md-offset-10">
<h6 id="dateTime">23/07/2015 12.00</h6>
</div>
</div>
</div>
</div>
<div class="panel-body">
</div>
<div class="panel-footer"></div>
"
Using only bootstrap, is it possible to center the two vertical labels of different dimensions (Current Job and Date) contained in Header panel (that contains a grid) and how to do it?
You need to alter the CSS for the following containers:
<div class="col-md-3"> and <div class="col-md-offset-10">
Giving both containers float: none; and margin: 0 auto will definitely center both. If you want the text to be centered as well, add some text-align: center
That should have you covered.
Sorry, forgot to mention that the container <div class="col-md-offset-10"> needs to match the width of the other container (25%).
You can do this by removing classes from your div tags for labels and giving text-center class to div with class row. This will make both labels appear in the middle of the page and one after another vertically. this is what your code container will look like:
<div class="container">
<div class="row text-center">
<div>
<h3><span class="label label-default">Current Job</span></h3>
</div>
<div>
<h6 id="dateTime">22/07/2015 12:00:00</h6>
</div>
</div>
</div>

Bootstrap: add margin/padding space between columns

I'm trying to put some extra margin/padding space between columns on my Bootstrap grid layout. I've tried this but I don't like the result. Here is my code:
<div class="row">
<div class="text-center col-md-6">
Widget 1
</div>
<div class="text-center col-md-6">
Widget 2
</div>
</div>
I want to add margin: 10px and padding:10px. Some people suggest to change their classes to col-md-5 with pull-left and pull-right, but the gap between them will be too large.
Simply add a div within col-md-6 that has the extra padding that you need. The col-md-6 is the 'backbone' to keep the column integrity, but you can add additional padding within it.
<div class="row">
<div class="text-center col-md-6">
<div class="classWithPad">Widget 1</div>
</div>
<div class="text-center col-md-6">
<div class="classWithPad">Widget 2</div>
</div>
</div>
CSS
.classWithPad { margin:10px; padding:10px; }
Bootstrap 5 (Update 2021)
Bootstrap 5 has still includes spacing utilities for padding. However, because of new RTL support "left" and "right" have been changed to "start" and "end". For example pl-2 is now ps-2.
pl-* => ps-* (padding-left)
pr-* => pe-* (padding-right)
ml-* => ms-* (margin-left)
mr-* => me-* (margin-right)
Additionally, Bootstrap 5 introduces new grid gutter classes that can be used to adjust the spacing between columns. The guttter is set on the row instead of each col-* inside the row. For example, use g-0 for no spacing between columns.
Bootstrap 5 column spacing demo
Bootstrap 4 (Update 2018)
Bootstrap 4 has spacing utilities that make adding (or substracting) the space (gutter) between columns easier. Extra CSS isn't necessary.
<div class="row">
<div class="text-center col-md-6">
<div class="mr-2">Widget 1</div>
</div>
<div class="text-center col-md-6">
<div class="ml-2">Widget 2</div>
</div>
</div>
You can adjust margins on the column contents using the margin utils such as ml-0 (margin-left:0), mr-0 (margin-right:0), mx-1 (.25rem left & right margins), etc...
Or, you can adjust padding on the columns (col-*) using the padding utils such as pl-0 (padding-left:0), pr-0 (padding-right:0), px-2 (.50rem left & right padding), etc...
Bootstrap 4 Column Spacing Demo
Notes
Changing the left/right margin(s) on col-* will break the grid.
Change the left/right margin(s) on the content of col-* works.
Change the left/right padding on the col-* also works.
I was facing the same issue; and the following worked well for me. Hope this helps someone landing here:
<div class="row">
<div class="col-md-6">
<div class="col-md-12">
Set room heater temperature
</div>
</div>
<div class="col-md-6">
<div class="col-md-12">
Set room heater temperature
</div>
</div>
</div>
This will automatically render some space between the 2 divs.
Just add 'justify-content-around' class. that would automatically add gap between 2 divs.
Documentation:
https://getbootstrap.com/docs/4.1/layout/grid/#horizontal-alignment
Sample:
<div class="row justify-content-around">
<div class="col-4">
One of two columns
</div>
<div class="col-4">
One of two columns
</div>
</div>
You may use the padding and margin shorthand Bootstrap 4 classes as follows:
For extra small devices i.e. xs
{property}{sides}-{size}
For other devices/viewports (small, medium, large and extra large)
{property}{sides}-{breakpoint}-{size}
Where:
property = m for margin and p for padding
Following are sides shorthand meanings:
l = defines the left-margin or left-padding
r = defines the right-margin or right-padding
t = defines the top-margin or top-padding
b = defines the bottom-margin or right-padding
x = For setting left and right padding and margins by the single call
y = For setting top and bottom margins
blank = margin and padding for all sides
The breakpoint = sm, md, lg, and xl.
Combining all the above, the left padding complete code can be (for example):
For left padding in extra small devices
pl-2
or for medium to extra large
pl-md-2
Try This:
<div class="row">
<div class="text-center col-md-6">
<div class="col-md-12">
Widget 1
</div>
</div>
<div class="text-center col-md-6">
<div class="col-md-12">
Widget 2
</div>
</div>
</div>
I would keep an extra column in the middle for larger displays and reset to default when the columns collapse on smaller displays. Something like this:
<div class="row">
<div class="text-center col-md-5 col-sm-6">
Widget 1
</div>
<div class="col-md-2">
<!-- Gap between columns -->
</div>
<div class="text-center col-md-5 col-sm-6">
Widget 2
</div>
</div>
Super easy with flexbox. Leave room for some space by changing the columns to col-md-5
<div class="row widgets">
<div class="text-center col-md-5">
Widget 1
</div>
<div class="text-center col-md-5">
Widget 2
</div>
</div>
CSS
.widgets {
display: flex;
justify-content: space-around;
}
For those looking to control the space between a dynamic number of columns, try:
<div class="row no-gutters">
<div class="col">
<div class="inner">
<!-- content here -->
</div>
</div>
<div class="col">
<div class="inner">
<!-- content here -->
</div>
</div>
<!-- etc. -->
</div>
CSS:
.col:not(:last-child) .inner {
margin: 2px; // Or whatever you want your spacing to be
}
A solution for someone like me when cells got background color
HTML
<div class="row">
<div class="col-6 cssBox">
a<br />ba<br />ba<br />b
</div>
<div class="col-6 cssBox">
a<br />b
</div>
</div>
CSS
.cssBox {
background-color: red;
margin: 0 10px;
flex-basis: calc(50% - 20px);
}
In the otherside if you like to remove double padding between columns just add class "nogap" inside row
<div class="row nogap">
<div class="text-center col-md-6">Widget 1</div>
<div class="text-center col-md-6">Widget 2</div>
</div>
and create additional css class for it
.nogap > .col{ padding-left:7.5px; padding-right: 7.5px}
.nogap > .col:first-child{ padding-left: 15px; }
.nogap > .col:last-child{ padding-right: 15px; }
Thats it, check here: https://codepen.io/michal-lukasik/pen/xXvoYJ
I had the same issue and worked it out by nesting a div inside bootstrap col and adding padding to it. Something like:
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="custom-box">Your content with padding</div>
</div>
<div class="col-md-4">
<div class="custom-box">Your content with padding</div>
</div>
<div class="col-md-4">
<div class="custom-box">Your content with padding</div>
</div>
</div>
</div>
I have just found a solution that works for me, although it doesnt actually create a space between the boxes so may not be exactly what you are looking for.
border border-white
Doesn't actually create a space but gives the effect of space between cols. Only works if you have a bg-color obviously.
Try this:
<div class="row">
<div class="col-md-5">
Set room heater temperature
</div>
<div class="col-md-2"></div>
<div class="col-md-5">
Set room heater temperature
</div>
</div>
For the more curious, I have also found that adding
border: 5px solid white
or any other variant of your liking, to make it blend in, works superbly.

Bootstrap columns not responsive / fluid

I'm using the Bootstrap CSS Grid System for the first time and I have noticed that in Google Chrome when I resize the window (from small to large) the design is responsive and fluid with the Divs keeping their ratio size. In Mozilla Firefox this isn't the case, although the class="container-fluid" Divs will stretch with the resize the Divs within the row class divs keep their small sizes (they don't get any larger, don't stretch). I tried adding .col-sm-* after the .col-xs-* classes but this has no effect / makes no difference (see the comment in the code). Am I making a silly, nubie error? Can anyone answer my issue whilst I go through the Bootstrap Documentation?
<header>
<div class="container-fluid header">
<div class="row">
<div class="col-xs-2">☰</div>
<div class="col-xs-8 text-center">
<img src="../img/some-image.png" alt="Some Image">
<span class="strapline">Nice Strap line</span>
</div>
<div class="col-xs-2 col-sm-2 text-right"> + </div>
</div>
</div>
<div class="container-fluid search">
<div class="row">
<div class="col-xs-3"></div>
<div class="col-xs-6 text-center"></div>
<div class="col-xs-3 text-right"></div>
</div>
</div>
<!--col-sm-* added here... -->
<div class="container-fluid filter-menu">
<div class="row">
<div class="col-xs-4 col-sm-4 filter-buttons">
Menu Button 1
<span class="filter-green">12.03.14, 12:30</span>
</div>
<div class="col-xs-4 col-sm-4 filter-buttons">
Menu Filter
<span class="green-count">1</span>
</div>
<div class="col-xs-4 col-sm-4 filter-buttons-last">
Sort By
<span class="filter-green">Rating</span>
</div>
</div>
</div>
</header>
Please note that .filter-green, filter-buttons, .filter-menu, .text-center, .text-right, .header and .search are custom CSS classes that I have produced and these don't have any conflict with the Bootstrap Grid
UPDATE **
Please note that I think I may have to use the .row-fluid class and the make columns the same height I added the following overwrite on the following bootstrap class
// bootstrap overwrite...
.row {
display: table;
}
[class*="col-"] {
// float: none;
display: table-cell;
vertical-align: top;
}
I just started using the .row-fluid class instead of .row and I removed my clearfix overwrite which is above. Problem solved!