Skip to content

Instantly share code, notes, and snippets.

@tschortsch
Last active January 5, 2018 12:46
Show Gist options
  • Save tschortsch/8272699377d5df33a5c160827b747185 to your computer and use it in GitHub Desktop.
Save tschortsch/8272699377d5df33a5c160827b747185 to your computer and use it in GitHub Desktop.
Bootstrap 3 Clearfix for boxes of same width but different height
/* Bootstrap Clearfix for boxes of same width but different height */
/* Source: http://www.bluthemes.com/blog/3/clearing-bootstrap-3-columns */
/* Tablet */
@media (min-width:767px) {
/* Column clear fix */
.col-lg-1:nth-child(12n+1),
.col-lg-2:nth-child(6n+1),
.col-lg-3:nth-child(4n+1),
.col-lg-4:nth-child(3n+1),
.col-lg-6:nth-child(2n+1),
.col-md-1:nth-child(12n+1),
.col-md-2:nth-child(6n+1),
.col-md-3:nth-child(4n+1),
.col-md-4:nth-child(3n+1),
.col-md-6:nth-child(2n+1) {
clear: none;
}
.col-sm-1:nth-child(12n+1),
.col-sm-2:nth-child(6n+1),
.col-sm-3:nth-child(4n+1),
.col-sm-4:nth-child(3n+1),
.col-sm-6:nth-child(2n+1) {
clear: left;
}
}
/* Medium Desktop */
@media (min-width:992px) {
/* Column clear fix */
.col-lg-1:nth-child(12n+1),
.col-lg-2:nth-child(6n+1),
.col-lg-3:nth-child(4n+1),
.col-lg-4:nth-child(3n+1),
.col-lg-6:nth-child(2n+1),
.col-sm-1:nth-child(12n+1),
.col-sm-2:nth-child(6n+1),
.col-sm-3:nth-child(4n+1),
.col-sm-4:nth-child(3n+1),
.col-sm-6:nth-child(2n+1) {
clear: none;
}
.col-md-1:nth-child(12n+1),
.col-md-2:nth-child(6n+1),
.col-md-3:nth-child(4n+1),
.col-md-4:nth-child(3n+1),
.col-md-6:nth-child(2n+1),
:not([class*="col-md-"]).col-sm-1:nth-child(12n+1),
:not([class*="col-md-"]).col-sm-2:nth-child(6n+1),
:not([class*="col-md-"]).col-sm-3:nth-child(4n+1),
:not([class*="col-md-"]).col-sm-4:nth-child(3n+1),
:not([class*="col-md-"]).col-sm-6:nth-child(2n+1) {
clear: left;
}
}
/* Large Desktop */
@media (min-width:1200px) {
/* Column clear fix */
.col-md-1:nth-child(12n+1),
.col-md-2:nth-child(6n+1),
.col-md-3:nth-child(4n+1),
.col-md-4:nth-child(3n+1),
.col-md-6:nth-child(2n+1),
:not([class*="col-md-"]).col-sm-1:nth-child(12n+1),
:not([class*="col-md-"]).col-sm-2:nth-child(6n+1),
:not([class*="col-md-"]).col-sm-3:nth-child(4n+1),
:not([class*="col-md-"]).col-sm-4:nth-child(3n+1),
:not([class*="col-md-"]).col-sm-6:nth-child(2n+1),
.col-sm-1:nth-child(12n+1),
.col-sm-2:nth-child(6n+1),
.col-sm-3:nth-child(4n+1),
.col-sm-4:nth-child(3n+1),
.col-sm-6:nth-child(2n+1) {
clear: none;
}
.col-lg-1:nth-child(12n+1),
.col-lg-2:nth-child(6n+1),
.col-lg-3:nth-child(4n+1),
.col-lg-4:nth-child(3n+1),
.col-lg-6:nth-child(2n+1),
:not([class*="col-lg-"]).col-md-1:nth-child(12n+1),
:not([class*="col-lg-"]).col-md-2:nth-child(6n+1),
:not([class*="col-lg-"]).col-md-3:nth-child(4n+1),
:not([class*="col-lg-"]).col-md-4:nth-child(3n+1),
:not([class*="col-lg-"]).col-md-6:nth-child(2n+1),
:not([class*="col-lg-"]):not([class*="col-md-"]).col-sm-1:nth-child(12n+1),
:not([class*="col-lg-"]):not([class*="col-md-"]).col-sm-2:nth-child(6n+1),
:not([class*="col-lg-"]):not([class*="col-md-"]).col-sm-3:nth-child(4n+1),
:not([class*="col-lg-"]):not([class*="col-md-"]).col-sm-4:nth-child(3n+1),
:not([class*="col-lg-"]):not([class*="col-md-"]).col-sm-6:nth-child(2n+1)
{
clear: left;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment