Bootstrap 3: split page in four equal parts - html

I'm trying to split a section of my one-page site (using Bootstrap 3) into 4 equal parts but I can't get it to work.
I thought I could just add extra classes to each col-md-6 but the problem is actually that the height is aligned to the content and I can't use fixed heights because it should be responsive...
<section>
...
</section>
<section id="theproject" class="project">
<div class="container" >
<div class="row">
<div class="col-md-6">
</div>
TOPLEFT
<div class="col-md-6">
TOPRIGHT
</div>
</div>
<div class="row">
<div class="col-md-6">
BOTTOMLEFT
</div>
<div class="col-md-6">
BOTTOMRIGHT
</div>
</div>
</div>
</section>
My custom.css looks like this:
.project {
height: auto !important;
min-height: 100%;
overflow: hidden;
background: white;
font-family: 'Open Sans', sans-serif;
font-style: normal;
font-size: 16px;
}
Thanks for your help!

If I understand what you are asking, here is how you can split your bootstrap into 4 equal parts. The heights will adjust to match the height of the column with the most(tallest) content.
Here is the Bootply so you can try it out.
HTML
<div class="row equal">
<div class="col-xs-6 col-sm-3">
content
</div>
<div class="col-xs-6 col-sm-3">
content
</div>
<div class="col-xs-6 col-sm-3">
content
</div>
<div class="col-xs-6 col-sm-3">
content
</div>
</div>
CSS
.equal, .equal > div[class*='col-'] {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
flex:1 0 auto;
}
EDITED: Solution for 4 equal quadrants
See the working Bootply here
http://www.bootply.com/qmwjea4pG3#
Example Below
HTML
<div class="contents">
<div class="col-md-6 quarter" style="background-color:blue;">test</div>
<div class="col-md-6 quarter" style="background-color:red;">test</div>
<div class="col-md-6 quarter" style="background-color:yellow;">test</div>
<div class="col-md-6 quarter" style="background-color:green;">test</div>
CSS
html,body {
padding:0;
margin:0;
height:100%;
min-height:100%;
}
.quarter{
width:50%;
height:100%;
float:left;
}
.contents{
height:50%;
width:100%;
}

Related

Div not being centered when using margin: auto; (Bootstrap)

I have a working example website from the bootstrap template website and was analysing the code to understand how they created it. Namely how they centered the text on the first page located here. The code for that snipplet is,
<header class="masthead text-center text-white d-flex"> <!-- Background image set here -->
<div class="container m-auto">
<div class="row">
<div class="col-lg-10 mx-auto">
...
</div>
<div class="col-lg-8 mx-auto">
...
</div>
</div>
</div>
</header>
So then I noticed that the m-auto was doing the centering. However, when I attempt to create it from scratch for myself and create this basic code,
<style>
#frontpage {
height: 100vh;
width: 100vw;
}
</style>
<section id="frontpage">
<div class="container m-auto">
<div class="row">
<div class="col-8">
<h1> YOU CAN DO IT </h1>
</div>
<div class="col-8">
<h1> I should be centered </h1>
</div>
</div>
</div>
</section>
It doesn't center at all.
What am I forgetting here?
I would suspect that the container gets centered inside it's parent, which takes up the page.
you have copied the code but styles not included for them if guess correctly. anyway, I have corrected please try this one.
<style>
#frontpage {
height: 100vh;
width: 100%;
}
.center-me{
margin: auto;
width: 60%;
text-align: center;
}
</style>
<section id="frontpage">
<div class="center-me">
<div >
<h1> YOU CAN DO IT </h1>
</div>
<div >
<h1> I should be centered </h1>
</div>
</div>
</section>
Is this what you're after?
Version 1
https://codepen.io/panchroma/pen/YdEWZJ
HTML
<section id="frontpage">
<div class="container m-auto">
<div class="row">
<div class="col-8">
<h1> YOU CAN DO IT </h1>
</div>
<div class="col-8">
<h1> I should be centered </h1>
</div>
</div>
</div>
</section>
CSS
#frontpage{
background-color:pink;
height: 100vh;
width: 100vw;
}
.col-8{
border:1px solid grey;
margin-left:auto !important;
margin-right:auto !important;
text-align:center;
}
Version 2
This also centers the text vertically
https://codepen.io/panchroma/pen/KbygzX
HTML
<section id="frontpage">
<div class="container m-auto">
<div class="row vert-align">
<div class="col-8">
<h1>YOU CAN DO IT</h1>
</div>
<div class="col-8">
<h1> I should be centered </h1>
</div>
</div>
</div>
</section>
CSS
#frontpage{
background-color:pink;
height: 100vh;
width: 100vw;
}
.col-8{
margin-left:auto !important;
margin-right:auto !important;
text-align:center;
}
.row.vert-align{
position: absolute;
top: 50%;
left:50%;
-ms-transform: translateY(-50%);
transform: translate(-50%, -50%);
}

boostrap 4 Equal heights not working

What is the way of making div's have equal heights within the row?
it says everywhere that bootstrap4 is flex by default, but it doesn't work for some unknown reason
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="content" >
<div class="sub_title"> HISTORY </div>
<div class="desc"> Sometext </div>
</div>
</div>
</div>
<div class="row">
<div class="col-12 col-sm-6 col-md-6 col-lg">
<div class="content">
<div class="sub_title">
<div class="number"> 2012 </div>
</div>
<div class="desc"> some other text </div>
</div>
</div>
<div class="col-12 col-sm-6 col-md-6 col-lg ">
<div class="content">
<div class="sub_title">
<div class="number"> 2014 </div>
</div>
<div class="desc"> More text </div>
</div>
</div>
<div class="col-12 col-sm-6 col-md-6 col-lg ">
<div class="content">
<div class="sub_title">
<div class="number"> 2017 </div>
</div>
<div class="desc"> Text here too </div>
</div>
</div>
</div>
the scss
.content {
#extend .effect8;
background: white;
margin: 10px;
padding: 10px 30px 20px;
span {
display: block;
p {
font-weight: bold;
}
}
}
.sub_title {
font-size: 1.5em;
font-weight: 700;
text-transform: uppercase;
display: block;
color: $blue;
margin: 10px auto;
}
this is the scss for the content and the sub_title class
If you want .content to be full height on each .col, the content should have height:100%;. I don't know the CSS def of .effect8.
.content {
background: white;
margin: 10px;
padding: 10px 30px 20px;
height: 100%;
span {
display: block;
p {
font-weight: bold;
}
}
}
https://www.codeply.com/go/B4g6TlSDkA
Actually it depend of browser, e.g In Safari it may not work, and also in Internet Explorer may have unwanted behaviors.
If you're really want equal and avoid cross browser issue try JS solution e.g http://brm.io/jquery-match-height/

Height of rows to fill column - Bootstrap layout

I know this may be easy for most of you but I'm stuck with this issue.
I need to implement this design:
Layout Design
... and for now I've got this Current layout.The general structure is a row with col-3 and col-9, this col-9 has two rows, one for name and job title, and the other one for statistics in the page (col-3 for each of them). I need them to fill the height of his parent, but height property doesn't work. Which could be a clean solution? Thanks a lot.
Here is the structure, it's pretty simple tho.
<div class="row profile-header">
<div class="col-md-3 user-image text-center">
<img ...>
<span>..</span>
</div>
<div class="col-md-9">
<div class="row">
<div class="col-md-12">
<h2 class="text-white">...</h2>
<h4 class="text-muted">...</h4>
</div>
</div>
<div class="row text-center">
<div class="col-md-3 stat">
<h3>...</h3>
<small>...</small>
</div>
...
</div>
</div>
Use position: relative on the parent and then position:absolute; bottom: 0; on the children.
Nice explanation there.
Flexbox would be my recommendation although CSS tables might be an option too.
Codepen Demo
Snippet Demo (view Fullscreen)
.user-image {
background: pink;
}
.user-image img {
display: block;
margin: auto;
}
.profile-header {
display: flex;
}
.right {
background: #c0ffee;
display: flex;
flex-direction: column;
}
.stats {
margin-top: auto;
}
.stat {
background: lightgrey;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<div class="row profile-header">
<div class="col-md-3 user-image text-center">
<img src="http://www.fillmurray.com/300/200" alt="" />
<span>User Ranking</span>
</div>
<div class="col-md-9 right">
<div class="row">
<div class="col-md-12">
<h2 class="text-white">User Name</h2>
<h4 class="text-muted">reference</h4>
</div>
</div>
<div class="row text-center stats">
<div class="col-md-3 stat">
<h3>Some Stat</h3>
<small>Some Stat</small>
</div>
<div class="col-md-3 stat">
<h3>Some Stat</h3>
<small>Some Stat</small>
</div>
<div class="col-md-3 stat">
<h3>Some Stat</h3>
<small>Some Stat</small>
</div>
<div class="col-md-3 stat">
<h3>Some Stat</h3>
<small>Some Stat</small>
</div>
</div>
</div>

How to get equal content and sidebar (height)?

OK Im using bootstrap and i have main content and inside main content i have left and right side. On left side its content and on right side i have 8 boxes. I tried everything but i cant get equal left and right side.
.main-content{
float: left;
width: 100%;
position: relative;
}
.main-content .right-box.col-md-4{
width: 37.5%;
padding-left:0;
padding-right:0;
float:right;
position:absolute;
top:0;
bottom:0;
right: 0;
}
.main-content .left-box.col-md-8{
width:62.5%;
padding-left:0;
padding-right: 0;
background-color: #fff;
float: left;
position: relative;
}
FIDDLE: https://jsfiddle.net/rvqg3fd7/
and last div on right side need to be same height like div on left side..
I tried this but without succes.
Height is an element you shouldn't force in a Bootstrap powered website, simply because Bootstrap relies on it's vertical flexibility to respond to smaller devices. After all, this is the main purpose why anyone would use Bootstrap. Yet, if you do insist, then you must give each element a definite height and control such height with paddings.
You didn't provide a code we could use (not even the fiddle) so I'll post my demo so you can see the bootstrap classes architecture you need to achieve this;
Here is the HTML
<div class="container">
<div class="row main-content">
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="row">
<div class="box left">
</div>
</div>
</div>
<div class="col-xs-12 col-sm-6 col-md-6">
<div class="row">
<div class="box right">
<div class=" innerbox col-xs-12">
1
</div>
<div class=" innerbox col-xs-12">
2
</div>
<div class=" innerbox col-xs-12">
3
</div>
<div class=" innerbox col-xs-12">
4
</div>
<div class=" innerbox col-xs-12">
5
</div>
<div class=" innerbox col-xs-12">
6
</div>
<div class=" innerbox col-xs-12">
7
</div>
<div class=" innerbox col-xs-12">
8
</div>
</div>
</div>
</div>
</div>
</div>
And the CSS
.box.left{
background:red;
text-align:center;
color: white;
height:350px;
}
.box.right{
background:blue;
text-align:center;
color: white;
height:350px;
padding:10px
}
.innerbox{
background:lightgray;
text-align:center;
color: black;
height:30px;
margin-top:10px;
}
.main-content{
float: left;
width: 100%;
position: relative;
}
And the link to the DEMO

How to change the bg color on hover for entire row in bootstrap 3

Actuly i want to make a grid tiles like below image
My all columns comes in a parent div thats why i am unbale to change the bg color on hover for entire row.
If i use multiple rows as a parnet for cloumns than these columns wont comes correctly to each other.
HTML:
<div class="container grid-layout">
<div class="row">
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
<div class="col-xs-12 col-md-3 col-sm-3">
<div class="name">Supercity</div>
</div>
</div>
</div>
CSS:
.grid-layout .row .col-md-3{
text-align: center;
border-bottom:#eee solid 1px;
}
.grid-layout .row .col-md-3 > a{
padding:10px 0;
display: inline-block;
width:100%;
color:#999999;
outline: none;
}
.grid-layout .row .col-md-3 > a:hover{
color:#5fa9e3;
text-decoration: none;
}
.grid-layout .row .col-md-3:hover{
background: #f7f7f7;
cursor: pointer;
}
.name{
padding:15px 0;
}
Please let me know what would be the correct approach.
You can try this using CSS like this:
.row:hover div[class^="col-"]{
background-color: #dcdcdc;
}
Hope this is what you are looking for.
If you just want to change the .row background-color this will work.
$('body > div > div').on( "mouseover", function() {
$( this ).css( "background-color", "red" );
});