Bootstrap fluid heights on sections with columns - css

I'm building a site that has two section sizes.
The sizes are:
Full screen (height: 100%;)
Half screen (height: 50%;)
See screenshots:
Note the section with three columns (green, pink, blue).
This works before the columns collapse at col-md-4.
Once the columns collapse, they overflow their container (height: 50%) and then theres 3 columns at 50% height (150%) the extra 100% covers up the last section (100%).
How can I get the height to expand if the container overflows?
body, html {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
background-color: #fff4fd;
}
.wrapper {
height: 100%;
width: 100%;
position: relative;
}
.wrapper .content {
height: 100%;
width: 100%;
}
.home {
background-color: red;
background-attachment: fixed;
}
.what-we-do {
background-color: blue;
}
.our-work {
background-color: #93A8FF;
}
.our-ethos {
background-color: yellow;
}
.case-studies .row {
height: 100%;
margin: 0;
}
.case-studies .row > div {
height: 100%;
}
.case-studies .row > div.case-study-1 {
background-color: #D1F3F0;
}
.case-studies .row > div.case-study-2 {
background-color: #FFEBF1;
}
.case-studies .row > div.case-study-3 {
background-color: #D7EEF9;
}
.page.page-full {
height: 100%;
}
.page.page-half {
height: 50%;
}
/*# sourceMappingURL=app.css.map */
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="bower_components/modernizr/modernizr.js"></script>
<div class="wrapper">
<div class="content">
<div class="page page-full home"></div>
<div class="page page-half what-we-do"></div>
<div class="page page-half our-work"></div>
<div class="page page-half case-studies">
<div class="row">
<div class="col col-md-4 case-study-1"></div>
<div class="col col-md-4 case-study-2"></div>
<div class="col col-md-4 case-study-3"></div>
</div>
<div class="cleafix"></div>
</div>
<div class="cleafix"></div>
<div class="page page-full our-ethos clearfix"></div>
</div>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="bower_components/jquery/dist/jquery.min.js"><\/script>')
</script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="js/app.js"></script>
See screenshot:

Related

Bootstrap grid not working inside a dynamic width container

I have a requirement where I have to create 2 fixed width panels, one on right and one on left and I have to keep the center component responsive according to bootstrap classes.
I did something like this
Styles file
.c-row {
max-width: 100%;
margin: 0 auto;
}
.c-row .c-col-left {
width: 260px;
}
.c-row [class^='c-'] {
float: left;
height: 90vh;
background-color: white;
}
.c-row .c-col-center {
background-color: #e6e7fb;
width: calc(100% - (260px + 350px));
}
.c-row .c-col-right {
width: 350px;
}
Markup
<div class="c-row">
<div class="c-left">content</div>
<div class="c-center">
<div class="row">
<div class="col-md-6">c1</div>
<div class="col-md-6">c2</div>
</div>
</div>
<div class="c-right">content</div>
</div>
So my problem here is: The grid inside center class isn't working, it works fine if I remove the style width: calc(100% - (260px + 350px)); from center column.
is there any way I can still make it work without changing the custom grid outside?
Use flexbox which is integral to Bootstrap 4
.c-row {
max-width: 100%;
margin: 0 auto;
display: flex;
}
.c-row .c-left {
flex: 0 0 260px;
background: pink;
}
.c-row [class^='c-'] {
height: 90vh;
}
.c-row .c-center {
background-color: #e6e7fb;
flex: 1;
}
.c-row .c-right {
flex: 0 0 350px;
background: lightblue;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="c-row">
<div class="c-left">content</div>
<div class="c-center">
<div class="row">
<div class="col-md-6">c1</div>
<div class="col-md-6">c2</div>
</div>
</div>
<div class="c-right">content</div>
</div>
Codepen Demo
You can do it without custom flexbox use but only with the Bootstrap grid.
.col,
[class*="col-"] {
min-height: 90vh !important;
}
.c-left {
width: 260px !important;
background: lightpink;
}
.c-center-1 {
background-color: lightcoral;
}
.c-center-2 {
background-color: lightskyblue;
}
.c-right {
width: 350px !important;
background: lightblue;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="container-fluid">
<div class="c-row row flex-nowrap">
<div class="col-auto c-left">content</div>
<div class="col c-center">
<div class="row">
<div class="col-md-6 c-center-1">c1</div>
<div class="col-md-6 c-center-2">c2</div>
</div>
</div>
<div class="col-auto c-right">content</div>
</div>
</div>
(some !important just because how SO snippets work, see codepen demo)
Codepen Demo

css3 flex: How to create 2 columns with : 100% + fixed width?

I am trying to make a simple flex layout:
#header {
background-color: grey;
}
#container {
display:flex;
height: calc(100vh - 50px);
}
#chatAndUserContainer {
display: flex;
width: 100%;
}
#chatContainer {
background-color: red;
width:100%;
}
#usersContainer {
background-color: green;
width:320px;
}
<div id="header">header</div>
<div id="container">
<div id="chatAndUserContainer">
<div id="chatContainer">
chatContainer
</div>
<div id="usersContainer">
usersContainer
</div>
</div>
</div>
The problem is : when rendered, the width of #usersContainer is not 320px but... 274px !
Any idea on how to correct that ? (I need to use display:flex, not absolute)
You are facing the shrink effect. Since the total width (100% + 320px) is bigger than 100% both your elements will shrink equally to fit their parent container.
To avoid this you can disable the shrink for the second div:
#header {
background-color: grey;
}
#container {
display:flex;
height: calc(100vh - 50px);
}
#chatAndUserContainer {
display: flex;
width: 100%;
}
#chatContainer {
background-color: red;
width:100%;
}
#usersContainer {
background-color: green;
width:320px;
flex-shrink:0;
}
<div id="header">header</div>
<div id="container">
<div id="chatAndUserContainer">
<div id="chatContainer">
chatContainer
</div>
<div id="usersContainer">
usersContainer
</div>
</div>
</div>
Or don't use width:100% and replace it with flex:1 so that your first div will fill the remaining space left by the second one:
#header {
background-color: grey;
}
#container {
display:flex;
height: calc(100vh - 50px);
}
#chatAndUserContainer {
display: flex;
width:100%;
}
#chatContainer {
background-color: red;
flex:1;
}
#usersContainer {
background-color: green;
width:320px;
}
<div id="header">header</div>
<div id="container">
<div id="chatAndUserContainer">
<div id="chatContainer">
chatContainer
</div>
<div id="usersContainer">
usersContainer
</div>
</div>
</div>
You can use calc() in #chatContainer, or min-width in #usersContainer, or use them both like in example below.
#header {
background-color: grey;
}
#container {
display:flex;
height: calc(100vh - 50px);
}
#chatAndUserContainer {
display: flex;
width: 100%;
}
#chatContainer {
background-color: red;
width:calc(100% - 320px);
}
#usersContainer {
background-color: green;
width:320px;
min-width: 320px;
}
<div id="header">header</div>
<div id="container">
<div id="chatAndUserContainer">
<div id="chatContainer">
chatContainer
</div>
<div id="usersContainer">
usersContainer
</div>
</div>
</div>

Bootstrap Full page columns

I want to have two columns which fills up every time the full page size unattached from the given content.
The problem is that my solutions work until I began to scroll the page.
Example
html,body {
height: 100%;
min-height: 100%;
}
.left-content {
background: red;
}
.right-content {
background: green;
}
.container-fluid {
height: 100%;
}
.row {
height: 100%;
}
[class^="col-"] {
height: 100%;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-sm-6 left-content">
LEFT COLUMN
</div>
<div class="col-sm-6 right-content">
RIGHT COLUMN
</div>
</div>
</div>
Anyone have a solution for this problem?!
How about adding col-xs-6 that accommodates extra small screens as well:
html,body {
height: 100%;
min-height: 100%;
}
.left-content {
background: red;
}
.right-content {
background: green;
}
.container-fluid {
height: 100%;
}
.row {
height: 100%;
}
[class^="col-"] {
height: 100%;
}
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<div class="col-md-6 col-xs-6 left-content">
LEFT COLUMN
</div>
<div class="col-md-6 col-xs-6 right-content">
RIGHT COLUMN
</div>
</div>
</div>

How to make columns stretch to the footer in different screens?

I have a bootstrap layout with two columns. On screens higher then 1000px content block is not stretch to the footer. I need it to expand vertically depending on the height of the user's browser window.
I've tried height:100%, min-height:100%; etc.
See my code below.
<div id="wrapContent" class="wrapContent">
<div class="container">
<div class="row">
<header>
HEADER
</header>
</div>
</div>
<div class="container">
<div class="row">
<div id="content" class="content clearfix">
<div class="col-xs-12">
<div class="flex-container">
<div class="col-xs-8 leftBlock">
LEFT BLOCK
</div>
<div class="col-xs-4 rightBlock">
RIGHT BLOCK
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
<footer>
FOOTER
</footer>
</div>
</div>
html,body {
height: 100%;
min-height: 100%;
font-size: 1.2em;
}
.wrapContent {
overflow: visible !important;
height: auto !important;
min-height: 100%;
margin: 0 auto -71px;
padding-bottom: 70px;
background: #323742;
}
.container {
width: 1170px !important;
margin: 0 auto;
}
header {
overflow: visible;
height: 189px;
background: #222;
color: #fff;
}
.content {
min-height: 516px;
}
.flex-container {
min-height: 516px;
overflow: hidden;
margin-right: -15px;
margin-left: -15px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-flex: 1;
-webkit-flex: 1 0 auto;
-ms-flex: 1 0 auto;
flex: 1 0 auto;
}
.leftBlock {
background: #fff;
}
.rightBlock {
background: #ccc;
}
footer {
background: #222;
height: 71px;
color: #fff;
}
.div{
height: 100vh;
}
Add these lines to whatever container you want to stretch and it should work. I have tried it already :)
In your case:
.leftBlock, .rightBlock{
height: 100vh;
}
try this code, I think this is what you want.I wrote a full code for you.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<style type="text/css">
body{
margin: 0;
padding: 0;
}
.Header{
background-color: gray;
color: white;
height: 189px;
font-size: 25px;
}
.Bone{
background-color: orange;
color: white;
height: 400px;
color: white;
}
.Btwo{
background-color: red;
color: white;
height: 400px;
color: white;
}
.Footer{
background-color: black;
color: white;
height: 70px;
font-size: 25px;
}
</style>
<body>
<div class="container">
<div class="table-responsive">
<table class="table">
<thead>
<tr><div class="col-md-12 Header">Header</div></tr>
</thead>
<tbody>
<tr>
<div class="col-md-8 Bone">Left Block</div>
<div class="col-md-4 Btwo">Right Block</div>
</tr>
</tbody>
<tfoot>
<tr><div class="col-md-12 Footer">Footer</div></tr>
</tfoot>
</table>
</div>
</div>
</body>
</html>
just copy,paste and run it.if this is not the case tell me.
Thanks to everyone!
I've just wrote simple JS, and everythings works ok
function rightBlockHeight() {
var height = $( window ).height() - $( '#footer' ).height() - $( "#header" ).height();
$( '#content' ).css( 'min-height', height );
$( '.rightBlock' ).css( 'min-height', height );
}
$( document ).ready( function() {
rightBlockHeight();
} );
$( window ).resize( function() {
rightBlockHeight();
} );

CSS : Apply background to full width in a div with a fixed width

My page is divided in rows with limited width. (<div class='row'>)
I would like to apply a background (color) to each row, but I would like the back ground not to take into consideration the width limit of the div, is there a way to achieve this ?
Thanks!
Were you going for something like this? It'd be easier to answer your question if you provided a fiddle or atleast some code so we can help you with your problem.
I came to this solution:
<div class="row1">
...
</div>
<div class="row2">
...
</div>
.row1 {
background-color: red;
width: 100%;
height: 50%;
}
.row2 {
background-color: pink;
width: 100%;
height: 50%;
}
You can run it here: JSFiddle
This is possible with a pseudo-element, no need for additional HTML.
.wrapper {
width: 50%;
margin: auto;
}
[class^=row] {
height: 50px;
position: relative;
margin-bottom: 10px;
}
[class^=row]:before {
content: '';
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
height: 100%;
width: 100vw;
background: purple;
z-index: -1;
}
.row1 {
background-color: red;
}
.row2 {
background-color: pink;
}
<div class="wrapper">
<div class="row1">...</div>
<div class="row2">...</div>
</div>
You may be better to place each row inside a .container-fluid div with a {min-width: 100%} and a custom class for the colour you need
.container-fluid {
min-width: 100%
}
.row {
max-width: 300px;
margin: 0 auto;
padding: 10px;
}
.red {
background-color: red;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
<div class="container-fluid red">
<div class="row">
<p>Row Content 1</p>
</div>
</div>
<div class="container-fluid green">
<div class="row">
<p>Row Content 2</p>
</div>
</div>
<div class="container-fluid blue">
<div class="row">
<p>Row Content 3</p>
</div>
</div>

Resources