Here is my fiddle:
http://jsfiddle.net/nom4mxLt/
<div id="wrapper">
<div id="yellow">variable height (I put 200px but can change in realtime)</div>
<div id="red">This one should fill all remaining space, even when yellow resizes</div>
</div>
html, body {
width:100%;
height:100%;
margin:0;
}
#wrapper {
width:100%;
height:100%;
position:relative;
}
#yellow {
width:100%;
height:200px;
background-color:yellow;
}
#red {
position:absolute;
top:200px;
bottom:0;
min-height;250px;
left:0;
width:100%;
background-color:red;
}
This works good when yellow bar has static height, which is not the case in my work.
(without using JS please !)
You can use flexbox with align-items: stretch
http://jsfiddle.net/nom4mxLt/3/
html, body {
width:100%;
height:100%;
margin:0;
}
#wrapper {
width:300px;
height:100%;
position:relative;
display: flex;
flex-flow: column;
}
#first {
width:300px;
height:300px;
background-color:#F5DEB3;
}
#second {
background-color:red;
flex-grow:1;
}
<div id="wrapper">
<div id="first"></div>
<div id="second"></div>
</div>
you may use flex for this kind of layout:
html, body {
width:100%;
height:100%;
margin:0;
}
#wrapper {
display:flex;
flex-flow:column;
height:100%;
}
#yellow {
width:100%;
background-color:yellow;
}
#red {flex:1;/* i will use whole space avalaible remaining in the flex direction of my parent */
background-color:red;
}
<div id="wrapper">
<div id="yellow">variable height <br/> any height but maybe a max-height could come handy to avoid red one to disseapear</div>
<div id="red">This one should fill all remaining space, even when yellow resizes</div>
</div>
To allow wrapper to grow, then min-height can come also usefull
html, body {
width:100%;
height:100%;
margin:0;
}
#wrapper {
display:flex;
flex-flow:column;
min-height:100%;
}
#yellow {
background-color:yellow;
}
#red {flex:1;/* i will use whole space avalaible remaining in the flex direction of my parent */
background-color:red;
}
<div id="wrapper">
<h1>test and resize me in full page mode </h1>
<div id="yellow"> variable height <br/> any height<br/> but maybe a max-height<br/> could come handy <br/>to avoid red one to disseapear<br/> or min-heigh on wrapper</div>
<div id="red">This <br/>one <br/>should fill <br/>all remaining space,<br/> even when yellow resizes</div>
</div>
Here is also some usefull ressource on flex : https://css-tricks.com/snippets/css/a-guide-to-flexbox/
Related
* {
margin:0;
}
#container {
height:800px;
display:flex;
flex-direction:column;
justify-content:space-between;
background-color:grey;
}
#box-1 {
background-color:green;
height:400px;
flex:1
}
#box-2 {
background-color:yellow;
height:200px;
flex:1;
}
#box-3 {
background-color:pink;
height:100px;
flex:1;
}
<body>
<div id="container">
<div id="box-1"></div>
<div id="box-2"></div>
<div id="box-3"></div>
</div>
</body>
Can someone tell me if there's another way to put every div to 33% div so I wouldn't need to re calculate it each time I've added some margin/padding? I was wondering if there's anything I missed while learning flexbox. Thank you.
You missed flex-direction:row; see below:-
* {
margin:0;
}
#container {
height:800px;
display:flex;
flex-direction:column;
justify-content:space-between;
background-color:grey;
flex-direction:row;
}
#box-1 {
background-color:green;
height:400px;
flex:1
}
#box-2 {
background-color:yellow;
height:200px;
flex:1;
}
#box-3 {
background-color:pink;
height:100px;
flex:1;
}
<div id="container">
<div id="box-1"></div>
<div id="box-2"></div>
<div id="box-3"></div>
</div>
If you need 33% width (horizontal length) for the three div items, the container class needs flex-direction: row; instead of flex-direction: column;. The three div items will fill up the device width equally (33.3%)
if you meant 33% height (vertical length) for the three div items, you can add flex-basis: 33.3%; property to your box classes.
I am trying to make a 3 column website. Left and right columns are small 240px divs attached to the sides. The middle div is a stretchable area where all the elements inside stretch according to the size of the browser.
So far I have it set up like this :
body, html {
height:100%;
}
body {
margin:0;
}
.container {
background:orange;
height:100%;
width:100%;
overflow:hidden;
}
.left {
width:240px;
height:100%;
background:rgba(0,0,0,0.5);
position:absolute;
top:0;
left:0;
}
.middle {
width:100%;
height:100%;
background:orange;
}
.right {
width:240px;
height:100%;
background:rgba(0,0,0,0.5);
position:absolute;
top:0;
right:0;
}
And:
<div class="container">
<div class="left"></div>
<div class="middle">
// all the content
</div>
<div class="right"></div>
</div><!--container-->
How do I make the content in the middle column stay in between the left and right columns? I was thinking to use margin-left and margin-right but I feel it is not a good way of doing it.
Live:
http://codepen.io/daydreamer/pen/0479cc8de929cedc2ac519280a3044aa
If you are supporting modern browsers, I would try using flexbox:
.container {
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.container div {
flex-grow: 1;
height: 50px;
}
.side {
max-width: 240px;
min-width: 240px;
background: red;
}
<div class="container">
<div class="side"></div>
<div class="middle">
// all the content
</div>
<div class="side"></div>
</div>
jsfiddle example
Flexbox resource
You don't need to use margin-left, but margin-right would be useful. I would use float: left and get rid of position: absolute on the left sidebar, and use margin-right: 240px and get rid of width: 100% on the middle div.
CSS:
.left {
width:240px;
height:100%;
background:rgba(0,0,0,0.5);
top:0;
left:0;
float:left;
}
.middle {
height:100%;
background:orange;
margin-right: 240px;
}
.right {
width:240px;
height:100%;
background:rgba(0,0,0,0.5);
position:absolute;
top:0;
right:0;
}
Use Twitter Bootstrap to do n-column design and it will save you a lot of work. Right click on inspect the HTML code on the example page I provided and you'll see that all you need to do is set classes to a few div's and it works when you include the bootstrap JS/CSS files.
How can I let the green div be width: 100% with the other two divs on the same line with fixed width.
My idea is to let the two side div's have fixed width and the central div to be width: 100% (taking up the remainder space).
Is it possible to implement this situation?
CSS:
.boxMenu {
width:200px;
height:40px;
background-color:#000;
float:left;
}
.boxConteudoMaster {
height:40px;
background-color:#4cff00;
float:left;
}
.boxNotificacao {
width:200px;
height:40px;
background-color:#000;
float:left;
}
HTML:
<div class="boxMenu"></div>
<div class="boxConteudoMaster">asd</div>
<div class="boxNotificacao"></div>
JSFIDDLE HERE
I think your after something like this:
HTML:
<div class="boxMenu"></div>
<div class="boxNotificacao"></div>
<div class="boxConteudoMaster">Testing...</div>
CSS:
.boxMenu {
width:200px;
height:40px;
background-color:#000;
float:left;
}
.boxConteudoMaster {
height:40px;
background-color:#4cff00;
width: 100%;
}
.boxNotificacao {
width:200px;
height:40px;
background-color:#000;
float:right;
}
So we can float the 2 divs that we want fixed (float:left and float: right) and then after put are middle div to width: 100%.
DEMO HERE
I'm searching for a full-screen (height: 100%, width: 100%, so no scroll bars) fluid layout with a header and 2 colomns, the left one for the navigation menu and the right one for the content. Can anyone help me? Thanks.
FIDDLE
HTML
<div class='table'>
<div class='header'>Header</div>
<div class='row'>
<div class='cell'>Menu</div>
<div class='cell'>Content</div>
</div>
</div>
CSS
* {
box-sizing:border-box;
}
html, body {
width:100%;
height:100%;
overflow:hidden;
position:fixed;
margin:0;
padding:0;
}
.table {
display:table;
width:100%;
height:100%;
table-layout:fixed;
}
.row {
display:table-row;
}
.cell {
display:table-cell;
border:1px solid grey;
}
.header {
display:table-header-group;
border:1px solid grey;
}
I have the following issue with the next code posted in JSFiddle: http://jsfiddle.net/b9XVV/1/
HTML
<div class="content">
<div class="header">THGE HEADER OF THE PAGE</div>
<div class="thebody">
HERE GOES THE CONTENT OF THE PAGE......
</div>
<div class="footer">
<div class="footerContent">
<div class="footer1">Footer section</div>
<div class="footer2"></div>
</div>
</div>
</div>
CSS
.header {
width:100%;
height:50px;
background-color:#FFFF58;
}
.thebody {
width:500px;
height:400px;
margin:0 auto;
background-color:#DDD;
}
.footer {
width:500px;
height:50px;
background-color:#696969;
margin:0 auto;
}
.footerContent {
width:500px;
height:50px;
}
.footer1 {
width:400px;
height:50px;
float:left;
}
.footer2 {
width:100px;
height:50px;
float:left;
background-color:#FFddFF;
position:fixed;
right:0;
}
The question is that the pink Div should always stay on the footer and fixed on the right, but if window width is less than body width plus pink Div width, the pink Div should be kept on the left of the main footer (500px width)
Another issue is that scrolling the content, the pink div should always stay at the same level of the footer.
CSS:
.footer2 {
width:100px;
height:50px;
background-color:#FFddFF;
}
#media all and (max-width: 649px){
.footer2 {
position: inline;
float: right
}
}
#media all and (min-width: 650px){
.footer2 {
position:fixed;
right:0;
bottom: 0;
}
}
Demo: http://jsfiddle.net/b9XVV/2/
Watch the compatibility of the media queries: http://caniuse.com/#feat=css-mediaqueries Your main problem (if applicable) is IE8.