I'm trying to get 5 column full width layout but I can't find the solution that fits on my needs
Here's the code I use
<!-- Content Section -->
<div class="container">
<div class="row">
<div class="col-lg-12" style="border: 1px solid red">
<div class="row">
<div class="col-xs-12">
<div class="col-xs-2 col-xs-offset-1" id="p1">One</div>
<div class="col-xs-2" id="p2">Two</div>
<div class="col-xs-2" id="p3">Three</div>
<div class="col-xs-2" id="p4">Four</div>
<div class="col-xs-2" id="p5">Five</div>
</div>
<!-- //col-lg-12 -->
</div>
<!-- //row -->
lorem
</div>
</div>
<!-- //col-lg-12 -->
</div>
<!-- //row -->
</div>
<!-- //container -->
As a result I get
And here is what I'm trying to achieve. Full width 5 column layout with a space between each column
5 Columns with Bootstrap 4
Here is 5 equal, full-width columns (no extra CSS or SASS) using the auto-layout grid..
<div class="container-fluid">
<div class="row">
<div class="col">1</div>
<div class="col">2</div>
<div class="col">3</div>
<div class="col">4</div>
<div class="col">5</div>
</div>
</div>
http://codeply.com/go/MJTglTsq9h
This solution works because Bootstrap 4 is now flexbox. You can get the 5 colums to wrap within the same .row using a clearfix break such as <div class="col-12"></div> or <div class="w-100"></div> every 5 columns.
Update 2020
As of Bootstrap 4.4, you can also use the row-cols-5 class on the row...
<div class="container">
<div class="row row-cols-5">
<div class="col">
X
</div>
<div class="col">
X
</div>
<div class="col">
X
</div>
<div class="col">
X
</div>
<div class="col">
X
</div>
<div class="col">
X
</div>
</div>
</div>
https://codeply.com/p/psJLGuBuc3
UPDATE, 2021: for modern Bootstrap (4+), I recommend Zim's answer due to it's natural way of using Bootstrap flex classes
.col-xs-2{
background:#00f;
color:#FFF;
}
.col-half-offset{
margin-left:4.166666667%
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row" style="border: 1px solid red">
<div class="col-xs-2" id="p1">One</div>
<div class="col-xs-2 col-half-offset" id="p2">Two</div>
<div class="col-xs-2 col-half-offset" id="p3">Three</div>
<div class="col-xs-2 col-half-offset" id="p4">Four</div>
<div class="col-xs-2 col-half-offset" id="p5">Five</div>
<div>lorem</div>
</div>
</div>
This should be ok.
Default bootstrap(version 4.6) grid allows you to do this.
You can make 7, 7 11 columns in a row.
<div class="container">
<div class="row row-cols-5">
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
</div>
</div>
Responsive version of this.
<div class="container">
<div class="row row-cols-2 row-cols-sm-3 row-cols-md-4 row-cols-lg-5 row-cols-xl-5">
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
<div class="col">Column</div>
</div>
</div>
Just add this to your CSS
/* 5 Columns */
.col-xs-15,
.col-sm-15,
.col-md-15,
.col-lg-15 {
position: relative;
min-height: 1px;
padding-right: 10px;
padding-left: 10px;
}
.col-xs-15 {
width: 20%;
float: left;
}
#media (min-width: 768px) {
.col-sm-15 {
width: 20%;
float: left;
}
}
#media (min-width: 992px) {
.col-md-15 {
width: 20%;
float: left;
}
}
#media (min-width: 1200px) {
.col-lg-15 {
width: 20%;
float: left;
}
}
Sometimes I'm asked to use some pretty odd grid layouts in existing bootstrap websites (without messing up the current code). What I have done is create a separate CSS file which i can just drop into current bootstrap projects and use the grid layout styles in there. Here is what the bootstrap-5ths.css file contains along with an example of how it looks for bootstrap version 4.
If you want to use this with bootstrap version 3, just remove the col-xl-* styles and change the min-widths from 576px to 768px, 768px to 992px and 992px to 1200px.
.col-xs-5ths, .col-sm-5ths, .col-md-5ths, .col-lg-5ths, .col-xl-5ths,
.col-xs-two5ths, .col-sm-two5ths, .col-md-two5ths, .col-lg-two5ths, .col-xl-two5ths,
.col-xs-three5ths, .col-sm-three5ths, .col-md-three5ths, .col-lg-three5ths, .col-xl-three5ths,
.col-xs-four5ths, .col-sm-four5ths, .col-md-four5ths, .col-lg-four5ths, .col-xl-four5ths,
.col-xs-five5ths, .col-sm-five5ths, .col-md-five5ths, .col-lg-five5ths, .col-xl-five5ths,
{
position: relative;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
}
#media (min-width: 576px) {
.col-sm-5ths {width: 20%;float: left;}
.col-sm-two5ths {width: 40%;float: left;}
.col-sm-three5ths {width: 60%;float: left;}
.col-sm-four5ths {width: 80%;float: left;}
}
#media (min-width: 768px) {
.col-md-5ths {width: 20%;float: left;}
.col-md-two5ths {width: 40%;float: left;}
.col-md-three5ths {width: 60%;float: left;}
.col-md-four5ths {width: 80%;float: left;}
}
#media (min-width: 992px) {
.col-lg-5ths {width: 20%;float: left;}
.col-lg-two5ths {width: 40%;float: left;}
.col-lg-three5ths {width: 60%;float: left;}
.col-lg-four5ths {width: 80%;float: left;}
}
#media (min-width: 1200px) {
.col-xl-5ths {width: 20%;float: left;}
.col-xl-two5ths {width: 40%;float: left;}
.col-xl-three5ths {width: 60%;float: left;}
.col-xl-four5ths {width: 80%;float: left;}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-5ths">1</div>
<div class="col-md-5ths">1</div>
<div class="col-md-5ths">1</div>
<div class="col-md-5ths">1</div>
<div class="col-md-5ths">1</div>
</div>
<div class="row">
<div class="col-md-5ths">1</div>
<div class="col-md-two5ths">2</div>
<div class="col-md-two5ths">2</div>
</div>
<div class="row">
<div class="col-md-three5ths">3</div>
<div class="col-md-two5ths">2</div>
</div>
<div class="row">
<div class="col-md-four5ths">4</div>
<div class="col-md-5ths">1</div>
</div>
<div class="row">
<div class="col-md-five5ths">5</div>
</div>
</div>
<div class="row">
<div class="col">One</div>
<div class="col">Two</div>
<div class="col">Three</div>
<div class="col">Four</div>
<div class="col">Five</div>
</div>
you can customize however you need by writing media query. So that we can maintain responsive design
#media(max-width: 425px) {
.col {
flex-basis: auto;
-webkit-box-flex: 1;
flex-grow: 1;
max-width: 100%;
}
}
#media(min-width: 426px) and (max-width: 961px){
.col {
flex-basis: auto;
-webkit-box-flex: 1;
flex-grow: 1;
max-width: 50%;
}
}
CSS
.bg{
background-color: #9DC3E6;
border-radius: 10px;
color: #fff;
padding: 15px;
}
.col-xs-5-cols,
.col-sm-5-cols,
.col-md-5-cols,
.col-lg-5-cols {
position: relative;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
}
.col-xs-5-cols {
width: 20%;
float: left;
}
#media (min-width: 768px) {
.col-sm-5-cols {
width: 20%;
float: left;
}
}
#media (min-width: 992px) {
.col-md-5-cols {
width: 20%;
float: left;
}
}
#media (min-width: 1200px) {
.col-lg-5-cols {
width: 20%;
float: left;
}
}
html
<div className="row">
<div className="col-md-5-cols">1<div className="bg"></div></div>
<div className="col-md-5-cols">2<div className="bg"></div></div>
<div className="col-md-5-cols">3<div className="bg"></div></div>
<div className="col-md-5-cols">4<div className="bg"></div></div>
<div className="col-md-5-cols">5<div className="bg"></div></div>
</div>
If you want to enforce the 20% column width for every row that you have, even if you don't have 5 columns in some rows, you will have to add the following to your css or scss file:
.col-xs-5-cols,
.col-sm-5-cols,
.col-md-5-cols,
.col-lg-5-cols {
position: relative;
width: 100%;
min-height: 1px;
padding-right: 15px;
padding-left: 15px;
}
.col-xs-5-cols {
-ms-flex: 0 0 20%;
flex: 0 0 20%;
max-width: 20%;
}
#media (min-width: 768px) {
.col-sm-5-cols {
-ms-flex: 0 0 20%;
flex: 0 0 20%;
max-width: 20%;
}
}
#media (min-width: 992px) {
.col-md-5-cols {
-ms-flex: 0 0 20%;
flex: 0 0 20%;
max-width: 20%;
}
}
#media (min-width: 1200px) {
.col-lg-5-cols {
-ms-flex: 0 0 20%;
flex: 0 0 20%;
max-width: 20%;
}
}
And in your html, use the added class as following:
<div class="row">
<div class="col-lg-5-cols"></div>
<div class="col-lg-5-cols"></div>
<div class="col-lg-5-cols"></div>
<div class="col-lg-5-cols"></div>
<div class="col-lg-5-cols"></div>
</div>
Why not using grid?
.container {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
grid-column-gap: 20px
}
Put some margin-left in all green divs but not in the first
Take a look at this page for general Boostrap layout information http://getbootstrap.com/css/#grid-offsetting
Try this:
<div class="col-xs-2" id="p1">One</div>
<div class="col-xs-3">
<div class="col-xs-8 col-xs-offset-2" id="p2">Two</div>
</div>
<div class="col-xs-2" id="p3">Three</div>
<div class="col-xs-3">
<div class="col-xs-8 col-xs-offset-2" id="p4">Four</div>
</div>
<div class="col-xs-2" id="p5">Five</div>
I've split the width into 5 uneven div with col-xs- 2,3,2,3,2 respectively. The two div with col-xs-3 are 1.5x the size of the col-xs-2 div, so the column width needs to be 2/3x (1.5 x 2/3 = 1) the col-xs-3 widths to match the rest.
That's better, you can use any div count.
.col-xs-2{
background:#00f;
color:#FFF;
}
.col_item {
margin-left:4.166666667%
}
.col_item:first-child,
.col_item:nth-child(5n+1) {
margin-left: 0;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row" style="border: 1px solid red">
<div class="col-xs-2 col_item" id="p1">One</div>
<div class="col-xs-2 col_item" id="p2">Two</div>
<div class="col-xs-2 col_item" id="p3">Three</div>
<div class="col-xs-2 col_item" id="p4">Four</div>
<div class="col-xs-2 col_item" id="p5">Five</div>
<div class="col-xs-2 col_item" id="p5">One</div>
</div>
</div>
The best way to honestly do this is to change the number of columns you have instead of trying to bodge 5 into 12.
The best number you could probably use is 20 as it's divisble by 2, 4 & 5.
So in your variables.less look for: #grid-columns: 12 and change this to 20.
Then change your html to:
<div class="row">
<div class="col-xs-20">
<div class="col-xs-4" id="p1">One</div>
<div class="col-xs-4" id="p2">Two</div>
<div class="col-xs-4" id="p3">Three</div>
<div class="col-xs-4" id="p4">Four</div>
<div class="col-xs-4" id="p5">Five</div>
</div>
<!-- //col-lg-20 -->
</div>
I'd personally use display: flex for this as bootstrap isn't designed greatly for a 5 column split.
Copypastable version of wearesicc's 5 col solution with bootstrap variables:
.col-xs-15,
.col-sm-15,
.col-md-15,
.col-lg-15 {
position: relative;
min-height: 1px;
padding-right: ($gutter / 2);
padding-left: ($gutter / 2);
}
.col-xs-15 {
width: 20%;
float: left;
}
#media (min-width: $screen-sm) {
.col-sm-15 {
width: 20%;
float: left;
}
}
#media (min-width: $screen-md) {
.col-md-15 {
width: 20%;
float: left;
}
}
#media (min-width: $screen-lg) {
.col-lg-15 {
width: 20%;
float: left;
}
}
can use as below in bootstrap3:
<div class="row">
<div class="col-md-2 col-md-offset-1">One</div>
<div class="col-md-2">Two</div>
<div class="col-md-2">Three</div>
<div class="col-md-2">Four</div>
<div class="col-md-2">Five</div>
</div>
Instead of adding margin why not add a padding-right of 1px to each col-xs-2 coz padding would be still a part of that div
.col-xs-2 :not(.col-xs-2:nth-child(5))
{padding-right:1px}
.col-xs-2{
background:#00f;
color:#FFF;
}
.col-half-offset{
margin-left:4.166666667%
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row" style="border: 1px solid red">
<div class="col-xs-4" id="p1">One</div>
<div class="col-xs-4 col-half-offset" id="p2">Two</div>
<div class="col-xs-4 col-half-offset" id="p3">Three</div>
<div>Test</div>
</div>
</div>
In bootstrap 4 and latest bootstrap 5 has become more simpler to handle 5 Column layout in big screen it will show 5 item, medium screen it will show 3 item, in small screen it will show 2 item with center alignment.
<div class="row justify-content-center">
<div class="col-sm-6 col-md-4 col-lg">One</div>
<div class="col-sm-6 col-md-4 col-lg">Two</div>
<div class="col-sm-6 col-md-4 col-lg">Three</div>
<div class="col-sm-6 col-md-4 col-lg">Four</div>
<div class="col-sm-6 col-md-4 col-lg">Five</div></div>
Here is another simple way of doing this, by adding width 20% to every col-xs-2:
<div class="col-xs-12">
<div class="col-xs-2" style="width:20%;" id="p1">One</div>
<div class="col-xs-2" style="width:20%;" id="p2">Two</div>
<div class="col-xs-2" style="width:20%;" id="p3">Three</div>
<div class="col-xs-2" style="width:20%;" id="p4">Four</div>
<div class="col-xs-2" style="width:20%;" id="p5">Five</div>
</div>
What about using offset?
<div class="row">
<div class="col-sm-8 offset-sm-2 col-lg-2 offset-lg-1">
1
</div>
<div class="col-sm-8 offset-sm-2 col-lg-2 offset-lg-0">
2
</div>
<div class="col-sm-8 offset-sm-2 col-lg-2 offset-lg-0">
3
</div>
<div class="col-sm-8 offset-sm-2 col-lg-2 offset-lg-0">
4
</div>
<div class="col-sm-8 offset-sm-2 col-lg-2 offset-lg-0">
5
</div>
</div>
Related
I'm trying to create the following layout for one of my web projects. What's the best way to create that using HTML, CSS (Flex)?
I'm struggling with bottom-margin for C & D in Desktop screens, for D in Mobile screens.
As we don't have your code, so based on your question here i provide solution let me know if you have any question..
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container">
<div class="row">
<div class="col-md-6 mb-5">
<div class="card p-5">
A
</div>
</div>
<div class="col-md-6 mb-5">
<div class="card p-5">
B
</div>
</div>
<div class="col-md-6 mb-5">
<div class="card p-5">
C
</div>
</div>
<div class="col-md-6 mb-5">
<div class="card p-5">
D
</div>
</div>
</div>
</div>
You can do it like this.
.main_container {
display: grid;
grid-template-columns: auto auto;
grid-row-gap: 30px;
grid-column-gap: 30px;
}
.sections {
height: 200px;
text-align: center;
background-color: aqua;
}
/*here for mobiles inside mobile media query put this*/
.main_container {
display: grid;
grid-template-columns: auto;
grid-row-gap: 30px;
grid-column-gap: 30px;
}
<div class="main_container">
<div class="sections">A</div>
<div class="sections">B</div>
<div class="sections">C</div>
<div class="sections">D</div>
</div>
<div class="row">
<div class="col-md-6 col-lg-6 col-xl-6 col-sm-12 col-xs-12">
<p>Write text here A</p>
</div>
<div class="col-md-6 col-lg-6 col-xl-6 col-sm-12 col-xs-12">
<p>Write text here B</p>
</div>
</div>
<div class="cs-t20">
<!-- spacer -->
</div>
</div>
<div class="row">
<div class="col-md-6 col-lg-6 col-xl-6 col-sm-12 col-xs-12">
<p>Write text here C</p>
</div>
<div class="col-md-6 col-lg-6 col-xl-6 col-sm-12 col-xs-12">
<p>Write text here D</p>
</div>
</div>
<div class="cs-t20">
<!-- spacer -->
</div>
</div>
<style>
.cs-t20{
width: 100%;
height: 30px;
}
</style>
Hope it will help you!! All the Best !!
here your go..
.cs-t20 {
width: 100%;
height: 30px;
}
.continer {
width: 100%;
height: 100%;
}
.webpage-page-display {
float: none;
display: table-cell;
}
.webpage-page-column {
z-index: 1;
float: left;
position: relative;
min-height: 1px;
}
.webpage-page-half {
margin-left: 6%;
width: 47%;
}
.webpage-page-first {
margin-left: 0px;
clear: left;
}
.webpage-page-half {
width: 100%;
}
.webpage-page-column {
margin: 0;
margin-bottom: 20px;
width: 100%;
}
#media only screen and (min-width: 320px) and (max-width: 767px) {
.webpage-page_column_table_cell {
display: block;
}
.webpage-page-half {
width: 100%;
}
.webpage-page-column {
margin: 0;
margin-bottom: 20px;
width: 100%;
}
}
<div id="webpage_section">
<div class="container">
<div class="webpage-page-column webpage-page_column_table_cell webpage-page-first webpage-page-half webpage-page-display">
<p>Write text here A</p>
</div>
<div class="webpage-page-column webpage-page_column_table_cell webpage-page-half webpage-page-display">
<p>Write text here B</p>
</div>
<div class="cs-t20"></div>
</div>
</div>
<div id="webpage_section">
<div class="container">
<div class="webpage-page-column webpage-page_column_table_cell webpage-page-first webpage-page-half webpage-page-display">
<p>Write text here C</p>
</div>
<div class="webpage-page-column webpage-page_column_table_cell webpage-page-half webpage-page-display">
<p>Write text here D</p>
</div>
<div class="cs-t20"></div>
</div>
</div>
I have tried to change the column order in desktop view and mobile view. In mobile view, Last Name should be in 2nd place where in desktop, it should be in last.
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="row">
<div class="container active col-md-3 col-sm-6 ">
<div class="panel panel-default">
<div class="panel-heading">First Name</div>
</div>
</div>
<div class="container active col-md-3 col-sm-6 col-md-push-6">
<div class="panel panel-default">
<div class="panel-heading">Last Name</div>
</div>
</div>
<div class="container active col-md-3 col-sm-6 col-md-pull-3">
<div class="panel panel-default">
<div class="panel-heading">Address</div>
</div>
</div>
<div class="container active col-md-3 col-sm-6 col-md-pull-3 ">
<div class="panel panel-default">
<div class="panel-heading">Company</div>
</div>
</div>
</div>
Using Flex and adding Media-Query will solve your problem very easily.
There will be a way to get it done using Bootstrap Grid, i.e using col-md-push-4 and etc.
But it's very much convenient using flex and adding order to inner elements.
Very useful Flexbox documentation.
.outer {
margin: 20px 20px;
display: flex;
flex-wrap: wrap;
}
/*For Mobile*/
#media (min-width: 400px) {
.inner {
width: 100%;
padding: 0px 20px;
}
.fn {
order: 1;
}
.ln {
order: 2;
}
.add {
order: 3;
}
.co {
order: 4;
}
}
/*For Desktop which we are working for*/
#media (min-width: 992px) {
.inner {
width: 50%;
padding: 0px 20px;
}
.fn {
order: 1;
}
.ln {
order: 3;
}
.add {
order: 2;
}
.co {
order: 4;
}
}
/*For Large Screen*/
#media (min-width: 1200px) {
.inner {
width: 25%;
padding: 0px 20px;
}
.fn {
order: 1;
}
.ln {
order: 4;
}
.add {
order: 2;
}
.co {
order: 3;
}
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="outer">
<div class="inner fn">
<div class="panel panel-default">
<div class="panel-heading" style="background:red; color:white;">First Name</div>
</div>
</div>
<div class="inner ln">
<div class="panel panel-default">
<div class="panel-heading" style="background:green; color:white;">Last Name</div>
</div>
</div>
<div class="inner add">
<div class="panel panel-default">
<div class="panel-heading" style="background:blue; color:white;">Address</div>
</div>
</div>
<div class="inner co">
<div class="panel panel-default">
<div class="panel-heading" style="background:orange; color:white;">Company</div>
</div>
</div>
</div>
I see that you are using push & pull which will only work for the desktop/tablet viewports.
Best is to develop for the mobile as per your need and then use push & pull for the desktop/tablet to make the re-arrangement.
I have achieved similar ordering using the same approach. It works very well.
Update:
Adding the plunker for the same : http://plnkr.co/edit/b2PNXyyXOsXUx51LweJI?p=preview
HTML
<!DOCTYPE html>
<html>
<head>
<link data-require="bootstrap#3.3.7" data-semver="3.3.7" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script data-require="bootstrap#3.3.7" data-semver="3.3.7" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-3 col-sm-push-3 cell cell-1">
1
</div>
<div class="col-xs-12 col-sm-3 col-sm-pull-3 cell cell-2">
2
</div>
<div class="col-xs-12 col-sm-3 cell cell-3">
3
</div>
<div class="col-xs-12 col-sm-3 cell cell-4">
4
</div>
</div>
</div>
</body>
</html>
CSS
.cell {
background: #eee;
margin: 1px;
padding: 20px 0;
text-align: center;
}
I'm trying to achieve something like the following page:
https://undsgn.com/uncode/homepages/blog-metro/
I have tried and was able to come as close as this: https://jsfiddle.net/futu7t1c/
But how can I get those 2 small-thumbs at the bottom to move up?
The order is big, small, small, big, small, small
<div id="blog-posts">
<div class="grid big-thumb">
Title
</div>
<div class="grid small-thumb">
Title
</div>
<div class="grid small-thumb">
Title
</div>
<div class="grid big-thumb">
Title
</div>
<div class="grid small-thumb">
Title
</div>
<div class="grid small-thumb">
Title
</div>
</div>
css
#blog-posts {
-moz-column-count: 1;
-webkit-column-count: 1;
column-count: 1;
-moz-column-gap: 0em;
-webkit-column-gap: 0em;
column-gap: 0em;
}
.grid {
background: #eee;
float: left;
position: relative;
color: #fff;
}
.big-thumb {
width: 50%;
height: 600px;
background: #aeaeae;
}
.small-thumb {
width: 25%;
height: 300px;
background: #353535;
}
To replicate that grid, you can make flex rows that have flex children that are also flex columns holding your images.
.flex {
display: flex;
}
.col {
flex-direction: column;
flex: 0 0 50%;
}
img {
max-width: 100%;
vertical-align: top;
}
<div class="flex row">
<div class="flex col">
<div class="big">
<img src="http://1.bp.blogspot.com/-hNC-oT6f-fY/TeXxO26yjvI/AAAAAAAAAOY/qfkOqdKkBi8/s1600/platon-photographer-putin-man-of-the-year-portrait.jpg">
</div>
<div class="flex row">
<div class="small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
<div class="small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
</div>
</div>
<div class="flex col">
<div class="flex row">
<div class="small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
<div class="small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
</div>
<div class="big">
<img src="http://1.bp.blogspot.com/-hNC-oT6f-fY/TeXxO26yjvI/AAAAAAAAAOY/qfkOqdKkBi8/s1600/platon-photographer-putin-man-of-the-year-portrait.jpg">
</div>
</div>
Well, that's how you'd do it using regular ol' html/css. But since you want to just have a bunch of elements that automatagically lay out like that, use masonry
$('.masonry').masonry({
itemSelector: '.item',
columnWidth: '.small'
});
body {
margin: 0;
}
.item {
float: left;
}
.big {
width: 50%;
}
.small {
width: 25%;
}
img {
width: 100%;
vertical-align: top;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://unpkg.com/masonry-layout#4/dist/masonry.pkgd.min.js"></script>
<div class="masonry">
<div class="item big">
<img src="http://1.bp.blogspot.com/-hNC-oT6f-fY/TeXxO26yjvI/AAAAAAAAAOY/qfkOqdKkBi8/s1600/platon-photographer-putin-man-of-the-year-portrait.jpg">
</div>
<div class="item small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
<div class="item small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
<div class="item big">
<img src="http://1.bp.blogspot.com/-hNC-oT6f-fY/TeXxO26yjvI/AAAAAAAAAOY/qfkOqdKkBi8/s1600/platon-photographer-putin-man-of-the-year-portrait.jpg">
</div>
<div class="item small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
<div class="item small">
<img src="https://i.stack.imgur.com/2C22p.jpg">
</div>
</div>
I'm trying to get this result with boostrap :
The idea would be that : the black square stay as a square, even with the right "rows" being resized (on mobile for example)
And the red rows would be having the same height/width (I failed that on the image, just a quick paint mockup)
I'd love to show you some code that would be a starting point but after a few hours I'm unable to achieve this effect...
I found that template that use this kind of structure :
Gridus
Using flexbox as a wrapper.
* {
box-sizing: border-box;
}
.flexbox {
display: flex;
justify-content: left;
align-items: flex-start;
}
.col-md-10 {
border: thin solid darkgray;
max-height: 50px;
overflow: hidden;
height: 50px;
width: 100%;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="row nopadding flexbox">
<a href="#">
<div class="col-md-4 vc-photo photo-01"><img src="http://placehold.it/150" /></div>
</a>
<div class="col-md-8 nopadding">
<div class="row nopadding">
<div class="col-md-10">
<p>Bla</p>
</div>
</div>
<div class="row nopadding">
<div class="col-md-10">
<p>Bla</p>
</div>
</div>
<div class="row nopadding">
<div class="col-md-10">
<p>Bla</p>
</div>
</div>
</div>
</div>
You mean something like this? I didn't bother with the borders, but I can put it if you like
.left-div {
background-color: pink;
height: 120px;
width: 120px;
float:left;
}
.right-div {
background-color: red;
height: 120px;
float:left;
}
.col-xs-12{
height: 40px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<div class="container">
<div class="row">
<div class="left-div">Column 1</div>
<div class="right-div">
<div class="row">
<div class="col-xs-12">Row 1</div>
<div class="col-xs-12">Row 2</div>
<div class="col-xs-12">Row 3</div>
</div>
</div>
</div>
</div>
I am trying to design a simple HTML game and the layout is comprises of two rows of 7 columns/tiles in a row, and one big column/tile on.
Or simple a simulation of this game here.
The middle tiles are 7 up and 7 down and a bigger tile to the left and right as is seen in the game.
I use a css script like:
.grid-row {
margin-bottom: 15px;
}
.grid-container {
position: absolute;
z-index: 1; }
.grid-row:after {
content: "";
display: block;
clear: both; }
.grid-cell {
width: 106.25px;
height: 106.25px;
margin-right: 15px;
float: left;
border-radius: 3px;
background: rgba(238, 228, 218, 0.35); }
The above generate my tiles in a container as required like:
<div class="row">
<div class="game-container">
<div class="grid-container">
<div class="grid-row">
<div class="grid-cell"></div>
<div class="grid-cell"></div>
<div class="grid-cell"></div>
<div class="grid-cell"></div>
<div class="grid-cell"></div>
<div class="grid-cell"></div>
<div class="grid-cell"></div>
</div>
<div class="grid-row">
<div class="grid-cell"></div>
<div class="grid-cell"></div>
<div class="grid-cell"></div>
<div class="grid-cell"></div>
<div class="grid-cell"></div>
<div class="grid-cell"></div>
<div class="grid-cell"></div>
</div>
</DIV>
</div>
</div>
However, I'm having difficulty generating the two big tiles. I thought of separating the rows into left, right and center columns like:
.column-left{ float: left; width: 10%; }
.column-right{ float: right; width: 10%; }
.column-center{ display: inline-block; width: 80%; }
And then adding my grid-row above into column-center class. Then creating to two column left and right above adding a single tile i called grid-mega-cell below:
.grid-cell {
width: 106.25px;
height: 212.50px;
margin-right: 15px;
float: left;
border-radius: 3px;
background: rgba(238, 228, 218, 0.35); }
The above still fails. I tried using bootstrap columns as well. Two big tiles in a div.col-md.col-md-offset-1 and the middle tiles in div.col-md-8. All still fails.
You can do this using default bootstrap classes. Use this markup, inside a .container:
<div class="row">
<!-- First Pane -->
<div class="col-md-2">...</div>
<!-- Middle Section -->
<div class="col-md-8">
<!-- First row of 4 divs -->
<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>
<!-- Second row of 4 divs -->
<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>
</div>
<!-- Last Pane -->
<div class="col-md-2">...</div>
</div>
To add 7 columns in a row, this answer provides a great solution. Basically, it overrides the row's behaviour by setting it to seven-cols using the following CSS, and then use 7 col-md-1s inside that row to have 7 equal columns (see the code snippet for the demo):
#media (min-width: 768px){
.seven-cols .col-md-1,
.seven-cols .col-sm-1,
.seven-cols .col-lg-1 {
width: 100%;
*width: 100%;
}
}
#media (min-width: 992px) {
.seven-cols .col-md-1,
.seven-cols .col-sm-1,
.seven-cols .col-lg-1 {
width: 14.285714285714285714285714285714%;
*width: 14.285714285714285714285714285714%;
}
}
HTML:
<div class="row seven-cols">
<div class="col-md-1">...</div>
<!-- 6 more of these -->
</div>
View the results in full page, to make sure that .col-md-* rules work. If you want the grid to work on small screens as well, simply replace all .col-md-* classes to .col-xs-* (or .col-sm-* based on your requirements).
.col-md-1, .col-md-2, .col-md-3 {
background: rgba(0, 0, 0, 0.1);
outline: 1px #000 solid;
}
#media (min-width: 768px){
.seven-cols .col-md-1,
.seven-cols .col-sm-1,
.seven-cols .col-lg-1 {
width: 100%;
*width: 100%;
}
}
#media (min-width: 992px) {
.seven-cols .col-md-1,
.seven-cols .col-sm-1,
.seven-cols .col-lg-1 {
width: 14.285714285714285714285714285714%;
*width: 14.285714285714285714285714285714%;
}
}
/**
* The following is not really needed in this case
* Only to demonstrate the usage of #media for large screens
*/
#media (min-width: 1200px) {
.seven-cols .col-md-1,
.seven-cols .col-sm-1,
.seven-cols .col-lg-1 {
width: 14.285714285714285714285714285714%;
*width: 14.285714285714285714285714285714%;
}
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="row">
<!-- First Pane -->
<div class="col-md-2">First<br><br>Pane</div>
<!-- Middle Section -->
<div class="col-md-8">
<!-- First row of 4 divs -->
<div class="row seven-cols">
<div class="col-md-1">R11</div>
<div class="col-md-1">R12</div>
<div class="col-md-1">R13</div>
<div class="col-md-1">R14</div>
<div class="col-md-1">R15</div>
<div class="col-md-1">R16</div>
<div class="col-md-1">R17</div>
</div>
<!-- Second row of 4 divs -->
<div class="row">
<div class="col-md-3">R21</div>
<div class="col-md-3">R22</div>
<div class="col-md-3">R23</div>
<div class="col-md-3">R24</div>
</div>
</div>
<!-- Last Pane -->
<div class="col-md-2">Last<br><br>pane</div>
</div>
Output screenshot:
html
<div class="row">
<div class="col-md-2">
text</div>
<div class="col-md-8">
<div class="row">
<div class="col-md-3">
text</div>
<div class="col-md-3">
text</div>
<div class="col-md-3">
text</div>
<div class="col-md-3">
text</div>
<div class="col-md-3">
text</div>
<div class="col-md-3">
text</div>
<div class="col-md-3">
text</div>
<div class="col-md-3">
text</div>
</div>
</div>
<div class="col-md-2">
text</div>
</div>
you can try this::
<div class="row">
<!-- First Pane -->
<div class="col-md-2"></div>
<!-- Middle Section -->
<div class="col-md-2">
<!-- upper part -->
<div class="row">
<div class="col-md-12"></div>
</div>
<!-- lower part -->
<div class="row">
<div class="col-md-12"></div>
</div>
</div>
<div class="col-md-2">
<!-- upper part -->
<div class="row">
<div class="col-md-12"></div>
</div>
<!-- lower part -->
<div class="row">
<div class="col-md-12"></div>
</div>
</div>
<div class="col-md-2">
<!-- upper part -->
<div class="row">
<div class="col-md-12"></div>
</div>
<!-- lower part -->
<div class="row">
<div class="col-md-12"></div>
</div>
</div>
<div class="col-md-2">
<!-- upper part -->
<div class="row">
<div class="col-md-12"></div>
</div>
<!-- lower part -->
<div class="row">
<div class="col-md-12"></div>
</div>
</div>
<!-- end of Middle Section -->
<!-- Last Pane -->
<div class="col-md-2"></div>
</div>