On a 768px breakpoint moving the order of right column first and then the left column below - css

I was able to do the Source Ordering using push and pull method. But what the whole right column comes on top of the left column. What i want to achieve is shown in the attached screenshot. Please guide me if there is a work around where i want the order after a 768px breakpoint

If there is a knonwn height on large-4 , you could use a floatting method and a pseudo element, to push dow the first element in order to leave room for second element.
DEMO:
#media only screen and (max-width: 767px) {
.row:before {
content:'';
float:right;
height:1.2em;
width:0;
margin-left:-0.25em;
}
.large-8 {
clear:right;
float:right;
}
.large-4 {
float:none!important;
}
}
You have the natural flex method if you do not mind leaving aside older browsers: DEMO
#media only screen and (max-width: 767px) {
.row{
display:flex;
flex-direction:column;
}
.large-8 {
order:2;
}
}

Add push/pull classes to reorder the source: http://foundation.zurb.com/docs/components/grid.html? Look under source ordering, in that section there is a good example for what you want to do.

Check the foundation documentation
You should read about source ordering.
Source Ordering
Using these source ordering classes, you can shift columns around between our breakpoints. This means if you place sub-navigation below main content on small displays, you have the option to position the sub-navigation on either the left or right of the page for large displays. Prefix push/pull with the size of the device you want to apply the styles to. medium-push-#, large-push-# is the syntax you'll use. Use large-reset-order to reset pushed or pulled columns to their original position on large screens.
Example:
<div class="row">
<div class="small-10 small-push-2 columns">10</div>
<div class="small-2 small-pull-10 columns">2, last</div>
</div>
<div class="row">
<div class="large-9 large-push-3 columns">9</div>
<div class="large-3 large-pull-9 columns">3, last</div>
</div>
<div class="row">
<div class="large-8 large-push-4 columns">8</div>
<div class="large-4 large-pull-8 columns">4, last</div>
</div>
<div class="row">
<div class="medium-7 small-5 small-push-7 medium-push-5 columns">7</div>
<div class="medium-5 small-7 small-pull-5 medium-pull-7 columns">5, last</div>
</div>
<div class="row">
<div class="medium-6 medium-push-6 columns">6</div>
<div class="medium-6 medium-pull-6 columns">6, last</div>
</div>
Try it in your code, you will see, that columns with "last" named comes first.

Related

Bootstrap row with empty col-md [duplicate]

This question already has answers here:
Bootstrap Grid System new line does not look nice
(4 answers)
Closed 5 years ago.
I have simple div with row class having child div with col-md-3 class.
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
</div>
I am getting for divs in first row, but my second row has space and then the remaining divs.
DIV1 DIV2 DIV3 DIV4
DIV5 DIV6 DIV7
I am guessing the issue to be with "DIV4", but not able to get the cause and fix for it.
Note: Bootstrap 4 doesn't seem to have this issue, as it uses flexbox rather than floats for the grid columns. For Bootstrap 3 or earlier, this is a limitation of floats.
If all your items are identical height, this isn't an issue, but if you have dynamic content AND a dynamic number of items, you've got a fight on your hands.
As some of the other answers have already suggested, you could add more elements to your markup. However, if you are using bootstrap along with a template where there's an unknown number of items (col--) being added to the row, it will usually take some sort of scripting to wrap the right number of items in each row. Also, for example if you have items that are 4 across (col-md-3) on large screens, but 3 across (col-md-4) on small screens, you'll end up with every 4th item on it's own row on small screens.
Thanks to CSS3, there are some ways to fix this alignment problem without scripting when your items are consitently using the same set of grid classes. If you add the class multi-row-helper to your bootstrap row, the CSS below will clear the float on the first item of each new line of items, keeping them from being affected by the irregular size of the items above.
/** EDIT: Updated the breakpoint to bootstrap defaults - I inadvertently had put in some custom ones...Replace the px values with the values of your breakpoints!! **/
.multi-row-helper div[class~="col-xs-2"]:nth-child(6n+1),
.multi-row-helper div[class~="col-xs-3"]:nth-child(4n+1),
.multi-row-helper div[class~="col-xs-4"]:nth-child(3n+1),
.multi-row-helper div[class~="col-xs-6"]:nth-child(2n+1) {
clear: left;
}
#media (min-width: 768px) {
.multi-row-helper.row > div[class*="col-xs-"] {
clear: none;
}
.multi-row-helper div[class~="col-sm-2"]:nth-child(6n+1),
.multi-row-helper div[class~="col-sm-3"]:nth-child(4n+1),
.multi-row-helper div[class~="col-sm-4"]:nth-child(3n+1),
.multi-row-helper div[class~="col-sm-6"]:nth-child(2n+1) {
clear: left;
}
}
#media (min-width: 992px) {
.multi-row-helper.row > div[class*="col-sm-"] {
clear: none;
}
.multi-row-helper div[class~="col-md-2"]:nth-child(6n+1),
.multi-row-helper div[class~="col-md-3"]:nth-child(4n+1),
.multi-row-helper div[class~="col-md-4"]:nth-child(3n+1),
.multi-row-helper div[class~="col-md-6"]:nth-child(2n+1) {
clear: left;
}
}
Not the simplest solution, but if you use a lot of repeating grids, such as for an e-commerce product grid, on your site, it's often well worth a few extra lines of CSS to solve this issue.
For what it's worth, it's a little prettier using SCSS:
.multi-row-helper {
div[class~="col-xs-2"]:nth-child(6n+1),
div[class~="col-xs-3"]:nth-child(4n+1),
div[class~="col-xs-4"]:nth-child(3n+1),
div[class~="col-xs-6"]:nth-child(2n+1)
{clear:left;}
#media (min-width:768px) {
&.row > div[class*="col-xs-"]
{clear:none;}
div[class~="col-sm-2"]:nth-child(6n+1),
div[class~="col-sm-3"]:nth-child(4n+1),
div[class~="col-sm-4"]:nth-child(3n+1),
div[class~="col-sm-6"]:nth-child(2n+1)
{clear:left;}
}
#media (min-width:992px) {
&.row > div[class*="col-sm-"]
{clear:none;}
div[class~="col-md-2"]:nth-child(6n+1),
div[class~="col-md-3"]:nth-child(4n+1),
div[class~="col-md-4"]:nth-child(3n+1),
div[class~="col-md-6"]:nth-child(2n+1)
{clear:left;}
}
}
Avinash !!
Every row in bootstrap can have columns of size "12" so in your case columns size is 18 thats why, so after three divs size (12) is filled and its making space.
create two rows and put 3-3 divs in them.
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
</div>
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
<div class="col-md-3">
</div>
</div>
</div>
It will work :)

Bootstrap 3 - Remove guttering

Is it possible to remove the padding from one particular grid within Boostrap 3 -
I need to layout images responsively but the design requires no gaps between columns.
Bootstrap 3 introduced row-no-gutters in v3.4.0
https://getbootstrap.com/docs/3.4/css/#grid-remove-gutters
Yep you can do it by creating a custom style sheet and adding a additional css selector to the col class. [http://www.bootply.com/FtnGzu0dea][1]
/* CSS used here will be applied after bootstrap.css */
.thumbnails {
padding: 0;
}
<div class="wrapper">
<div class="container">
<div class="col-md-3 thumbnails">
<div class="thumbnail"><img src="http://placehold.it/350x150"></div>
</div>
<div class="col-md-3 thumbnails">
<div class="thumbnail"><img src="http://placehold.it/350x150"></div>
</div>
<div class="col-md-3 thumbnails">
<div class="thumbnail"><img src="http://placehold.it/350x150"></div>
</div>
<div class="col-md-3 thumbnails">
<div class="thumbnail"><img src="http://placehold.it/350x150"></div>
</div>
</div>
</div>
[1]: http://www.bootp
ly.com/FtnGzu0dea
My suggestion is to add a class for removing the padding at a certain media query width. Here is a test case that uses a header image that should respect the padding at all but the small size. At that point it has no padding and fits the full width of the viewport. I highly recommend using #screen-xs-max if you are compiling LESS source files. It avoids the one pixel jump for media queries that use max-width.
http://jsfiddle.net/jmarikle/htmn5Lov/
CSS
#media (max-width: 767px) { /* replaced with #screen-xs-max if using LESS */
.sm-no-padding [class*=col-] {
padding: 0;
}
}
HTML
<div class="row sm-no-padding">
<div class="col-sm-12">
<img class="img-responsive" src="//placehold.it/2000x1000"/>
Image and/or content in a row where we remove the padding for small screens
</div>
</div>
If you want more granular control with columns rather than at the row level, just apply the class to the columns and change your selector to [class*=col-].sm-no-padding
You can also create a new CSS class and add the following code into your stylesheet.
Custom CSS:
.no-padding > [class*='col-'] {
padding-right:0;
padding-left:0;
}
new CSS to use into your HTML div
.no-padding

dynamically created bootstrap columns with different heights, float to left

Consider an unknown number of divs being created dynamically and styled using the bootstrap grid system. In this example, I'm using col-sm-4 so after every third block, we move to a new row. The blocks (divs) can be different heights, which is determined by the content within.
This is where I run into the layout problem. When moving to a new row, I want the fourth block to float to the left. This only happens when the left most div in the row above is also the shortest. I have pictures to illustrate.
Real Life:
The Dream:
The "correct" way to do this would be to wrap every three in a row class I beleive, but I'm not sure how to do this with dynamic content (could probably hack it) or if there's an easy css solution.
HTML:
<div class="row">
<div class="col-sm-12">
<div class="col-sm-4 block">
<div class="inner-block"></div>
</div>
<div class="col-sm-4 block">
<div class="inner-block"></div>
</div>
<div class="col-sm-4 block">
<div class="inner-block" style="height:150px"></div>
</div>
<div class="col-sm-4 block">
<div class="inner-block"></div>
</div>
</div>
</div>
CSS:
.block {
padding: 5px;
}
.inner-block {
height: 200px;
background-color: blue;
}
Plunker Example (expand preview to proper size)
If your system is unable to add first/last classes on every nth div, then you can use the nth-child css pseudo selector.
#media (min-width: 768px) {// For medium displays and above
.col-sm-4:nth-child(3n+1) { // We target every 3rd div but offset the count by 1 so that that 1st, 4th 7th etc divs are cleared
clear:both; // Clear the float
}
}

Zurb foundation div align issue

i am using zurb foundation for building website, but now i am facing a problem as follows
There are four columns in a row and one of them is not visible sometimes as per some conditions, the code is
<div class="row">
<div class="small-3 columns">1 ... </div>
<div class="small-3 columns" style="display:none;">2 ... </div>
<div class="small-3 columns">3 ... </div>
<div class="small-3 columns">4 ... </div>
</div>
Now the problem is when the div is disabled the empty space between them should be used by other divs, but it is not happening in my case,
I know, i am missing small point, but cant get it
here is the image of problem
I need the 4th div to be shifted to left, as 3rd div is shifted automatically, if 2nd div is display:none
The ZURB-Foundation (looks like you are using version 4) doesn't work like that by default.
What I usually do is create a .left {float: left !important;} class. If you apply that to your 4th div then it will do as you say.
However depending on your reason for doing this AND WHETHER THIS IS ONLY SUPPOSED TO APPLY TO DESKTOP/TABLET/MOBILE or ALL THREE, you might want to use
#media queries in the stylesheet to specify where and when.
Examples:
#media (query goes here) {
.row .columns:last-child {
float: left;
}
}
** OR **
.left {
float: left !important;
}
THEN
<div class="row">
<div class="small-3 columns">1 ... </div>
<div class="small-3 columns" style="display:none;">2 ... </div>
<div class="small-3 columns">3 ... </div>
<div class="small-3 columns left">4 ... </div>
</div>
Try this fiddle
HTML
<div class="row">
<div class="small-3 columns">1 ... </div>
<div class="small-3 columns" style="display:none;">2 ... </div>
<div class="small-3 columns">3 ... </div>
<div class="small-3 columns">4 ... </div>
</div>
CSS
div.columns
{
padding:10px;
background:#00bfff;
width:20%;
display:block;
float:left;
}
#jnelson thanks for the help, now i realized the power of !important, so i have created simple solution
.abc{
float:left !important;
}
This also worked correctly on all type of devices
You should not be changing the fundamental structure of how the columns are sized or work.
Instead you should just uses different classes. If you know that one column will be disabled, and I am assuming you are using javascript to do this. Then also use javascript to add the proper column width. If you have 3 columns instead of 4(due to one being display none) give the three columns a small-4. This line of thinking will also allow you to handle two columns (small-6).
If you absolutely have to use 3 columns I agree with the above posts that you need to change.
[class*="column"]+[class*="column"]:last-child {
float: right;
to
[class*="column"]+[class*="column"]:last-child {
float: left;

Order of DIVs on mobile with ZURB Foundation (Push/Pull)

Quick question involving foundation. If I want divs to go in order 1 then 2 on desktop and 2 then 1 on mobile, how would I accomplish this using Zurb?
<div class="row">
<div class="three columns">
</div>
<div class="nine columns">
</div>
</div>
Thanks so much for the help!
This can definitely be done. In your code you should order the div's based on how you would display it on the mobile, i.e. 2 then 1. For displaying it properly on larger screens you can override the default styling of the div's.
For testing purposes you can try:
<div class="row">
<div class="nine columns" style="float:right;">
</div>
<div class="three columns" style="float:left;">
</div>
</div>
While the above solution will work, I suggest not using inline styling. I would rather override using custom classes and/or #media tags.
Using those the code would be:
For the HTML:
<div class="row">
<div class="nine columns pull-right">
</div>
<div class="three columns pull-left">
</div>
</div>
For the CSS/Stylesheet:
#media only screen and (min-width: 768px) {
.pull-left {float: left !important;}
.pull-right {float: right !important;}
}
Not sure you can do this strictly with css, but with javascript you can add the pull-x classes when applicable.
theory:
Place the columns in the order you want for the mobile device, or small screens rather. Then in document.ready, check whether show-for-small is visibile or not, if not, you are on a larger screen and can apply push|pull classes to your columns of choice.
pseudo code, assuming you know push/pull technique:
// do this if not on small screen
if ( $('.show-on-small').css('display') == 'none' ) {
// pull or push the columns as needed
$('.myColumnsToPull-two').addClass('pull-two');
} else {
// might be a good idea to revert above change
}

Resources