I need to display the main part of the page to cover the rest of the screen without the header.
The L and R part should be 50% of the page width (having a possible padding), and also 100% of the main height (that is, the rest of the screen)
+-----------------------+
| header |
+-----------------------+
| | |
| L | R | } main
| | |
+-----------------------+
| footer |
+-----------------------+
Here is my code jsfiddle:
html, body {
height: 100%;
min-height: 100%;
margin: 0;
padding: 0;
}
header {
background-color: orange;
height: 50px;
width: 100%;
}
main {
background-color: green;
height: 100%;
margin:0;
padding: 10px;
/* changeable */
box-sizing:border-box;
background-clip: content-box;
}
main div {
padding: 10px;
height: 100%;
background-clip: inherit;
/* changeable */
width:30%; /* to set=50% */
float: left;
}
main .left {
background-color: yellow;
}
main .right {
background-color: red;
}
<header>This is the header content.</header>
<main>
<div class="left">50% width, 100% main height left</div>
<div class="right">50% width, 100% main height right</div>
</main>
<footer>This is the footer content.</footer>
PS.
I need to be compatible with "IE9 +" (so flexbox is not compatible)
The result at the first page load should be like in the following image:
Since the height of the header is known, you can use absolute positioning
header, main, footer {
position: absolute;
left: 0;
right: 0;
}
header {
top: 0;
height: 50px;
background-color: orange;
}
main {
top: 50px;
bottom: 0;
}
.left, .right {
position: absolute;
top: 0;
bottom: 0;
width: 50%;
}
.left {
left: 0;
background-color: yellow;
}
.right {
right: 0;
background-color: red;
}
footer {
top: 100%;
}
<header>This is the header content.</header>
<main>
<div class="left">50% width, 100% main height left</div>
<div class="right">50% width, 100% main height right</div>
</main>
<footer>This is the footer content.</footer>
The issue you are having is with the padding of the div's in the main container. with a little re-factoring of your css I've managed to get it to not over lap.
Here's demo: http://jsfiddle.net/h1tz5h8q/2/
main {
background-color: green;
height: 100%;
margin:0;
padding: 1%;
}
main div {
padding: 0px;
height: 100%;
background-clip: inherit;
width:49%;
float: left;
}
main .left {
background-color: yellow;
}
main .right {
background-color: red;
float: right;
}
Pure CSS solution, Totally responsive, Without fixing any height (header or footer)
Here's the Demo
The only downsize, is that you have to build your HTML in a certain order. (Footer comes before the columns)
<div class="Container">
<div class="Header">
<h1>Header</h1>
</div>
<div class="HeightTaker">
<div class="Wrapper Container Inverse">
<div>
<div class="Footer">
</div>
</div>
<div class="HeightTaker">
<div class="Wrapper Content">
<div class="Table">
<div class="Column C1">
</div>
<div class="Column C2">
</div>
<div class="Column C3">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
The column width may be fixed, or not.. to you're will.
P.S:
this is an old answer of mine, that have 3 columns in it, but you can change it to 2 without any problem.
Add your left and right sections to wrapper divs to handle the 50% width and padding.
html, body {
height: 100%;
min-height: 100%;
margin: 0;
padding: 0;
}
header {
background-color: orange;
height: 50px;
width: 100%;
}
main {
background-color: green;
height: 100%;
margin:0;
padding: 10px;
/* changeable */
box-sizing:border-box;
background-clip: content-box;
}
main .left, main .right {
padding: 0 10px;
height: 100%;
background-clip: inherit;
}
main .left {
background-color: yellow;
}
main .right {
background-color: red;
}
.wrapper {
width: 50%;
float: left;
height: 100%;
}
footer {
display: block;
margin-top: 10px;
}
<div class="wrapper">
<div class="left">50% width, 100% main height left</div>
</div>
<div class="wrapper">
<div class="right">50% width, 100% main height right</div>
</div>
please try this one:
Demo
Css code:
html, body {
height: 100%;
min-height: 100%;
margin: 0;
padding: 0;
}
header {
background-color: orange;
height: 50px;
width: 100%;
}
main {
background-color: green;
height: 100%;
margin:0;
padding: 2%;
}
main div {
padding: 0px;
height: 100%;
background-clip: inherit;
width:49%;
float: left;
}
main .left {
background-color: yellow;
}
main .right {
background-color: red;
float: right;
}
One of the not very elegant, but functional examples I got to manage is the one using the css height: calc(100% - 50px); function for the main element:
html, body {
height: 100%;
min-height: 100%;
margin: 0;
padding: 0;
}
header {
background-color: orange;
height: 50px;
width: 100%;
}
main {
background-color: green;
height: calc(100% - 50px);
width: 100%;
margin: 0;
float: left;
padding: 5px;
box-sizing:border-box;
background-clip: content-box;
}
main div {
padding: 10px;
height: 100%;
background-clip: content-box;
box-sizing:border-box;
width:50%;
float: left;
}
main .left {
background-color: yellow;
}
main .right {
background-color: red;
}
<header>This is the header content.</header>
<main>
<div class="left">50% width, 100% main height left</div>
<div class="right">50% width, 100% main height right</div>
</main>
<footer>This is the footer content.</footer>
And here is the corresponding JSFiddle.
The downsize, is that I
have to use a fixed header height;
have to use twice this header (I think to solve this using LESS file instead of the CSS one...).
Related
I have a super simple example with a wrapper div and another div inside this wrapper called header.
body {
margin: 0;
padding: 0;
background-color: #ccc;
}
.wrapper {
margin: 0 auto;
width: 300px;
height: 100vh;
background-color: yellow;
}
.header {
background-color: #06c;
height: 50px;
}
<div class="wrapper">
<div class="header">
logo
</div>
</div>
Is it possible that the inner div called header sticks out of the wrapper on both sides with lets say 20px or even 100viewport wodth?
If I understand you correctly you want the inner header to stick out 20px. You can do that with negative margins:
body {
margin: 0;
padding: 0;
background-color: #ccc;
}
.wrapper {
margin: 0 auto;
width: 300px;
height: 100vh;
background-color: yellow;
}
.header {
background-color: #06c;
height: 50px;
margin-left: -20px;
margin-right: -20px;
}
<div class="wrapper">
<div class="header">
logo
</div>
</div>
if you want it to stretch through the whole viewport, you might have to position the element absolutely and use left: 0; right: 0;, however IMO it would be cleaner to move the div out of the container in that case.
You could give it a negative left/right margin:
body {
margin: 0;
padding: 0;
background-color: #ccc;
}
.wrapper {
margin: 0 auto;
width: 300px;
height: 100vh;
background-color: yellow;
}
.header {
background-color: #06c;
height: 50px;
margin: 0 -20px;
}
<div class="wrapper">
<div class="header">
logo
</div>
</div>
How can I have div.fixed at 100% of the width of its parent .content? ... knowing that all widths will be variable, even .content
more or less what I need is .content with position: relative; div.fixed with the position: absolute; and width: 100%; But fixed at the top if I have a vertical scroll
and if possible without using JavaScript, only with CSS.
I was trying several things but none works, thank you for your time and help
.sidebar {
float: left;
background-color: red;
padding: 20px;
color: #fff;
}
.content {
float: left;
width: 40%;
padding: 20px;
background-color: #d5d2ca;
min-height: 900px;
box-sizing: border-box;
position: relative;
}
.fixed {
background-color: #aaffaa;
padding: 20px;
position: absolute;
box-sizing: border-box;
width: calc(100% - 40px);
}
.content p {
margin-top: 100px;
}
<div style="width: 90%; margin: 0 auto;">
<div class="sidebar">
the sidebar is going to have variable width
</div>
<div class="content">
<div class="fixed">
Fixed
</div>
<p>content</p>
</div>
</div>
100% of .content? That would be
width:calc(40% - 40px);
change that line:
<div style="width: 90%; margin: 0 auto;">
to
<div style="width: 100%; margin: 0 auto;">
also add to the class:
.fixed {
width: 100%;
}
and remove width:40%; from the .content
I am not sure if i understand the problem correctly, but if you want to make the fixed div to have 100% of its parent, then the following should work
.content {
position: relative;
}
.fixed {
width: 100%;
position: absolute;
}
For your question to be solved, must width of .content equal with width of .fixed so, use of:
.fixed {
width: inherit;
//so .fixed get width 40%
}
But,
.fixed have position:fixed, so 40% is relative to the screen's viewport,
and
.content is 40% relative to his parent[div with width:90%,(90% relative to body)].
in here ,we have to do something to measure both elements relative to one element.so,do this:
html,body {
width: 100%;
margin:0;
}
<div style="width:100%; margin:5px 70px;">
of 90% to 100%----^ ^---^-------optional
also, use margin-left:-20px for remove affect padding:20px in .content.
.fixed {
margin-left: -20px;
//more code...
}
Nowو you have both elements have width:40% relative to same element.
Note, Get Full Page to better see result.
* {
box-sizing: border-box;
}
html,body {
width: 100%;
margin:0;
}
.sidebar {
float: left;
background-color: red;
padding: 20px;
color: #fff;
}
.content {
float: left;
width: 40%;
padding: 20px;
background-color: #d5d2ca;
min-height: 900px;
position: relative;
}
.fixed {
background-color: #aaffaa;
padding: 20px;
margin-left: -20px;
position: fixed;
width: inherit;
}
.content p {
margin-top: 100px;
}
<div style="width:100%; margin:5px 70px;">
<div class="sidebar">
the sidebar is going to have variable width
</div>
<div class="content">
<div class="fixed">
Fixed
</div>
<p>content</p>
</div>
</div>
here is my code: http://jsfiddle.net/fxWg7/4041/
I want to make the left sidebar extend down to the footer dynamically. The footer is a sticky footer which means it will stay down there no matter how long the main content is.
I want the left sidebar to extend down to the footer no matter the height of the main content.
html {
position: relative;
min-height: 100%;
}
body {
margin: 0 0 50px;
/* bottom = footer height */
}
.container {
height: auto;
overflow: hidden;
}
.left {
width: 180px;
float: left;
background: #aafed6;
}
.right {
float: none;
/* not needed, just for clarification */
background: #e8f6fe;
/* the next props are meant to keep this block independent from the other floated one */
width: auto;
overflow: hidden;
}
footer {
width: 100%;
background-color: #000;
color: #fff;
padding: 1em;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
}
<div class="container">
<div class="left">
left content fixed width
<br>
<br> I want this to extend to footer!
</div>
<div class="right">
right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
</div>
</div>
<footer>
This is my footer.
</footer>
UPDATED:
The following css code will do it:
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
.container {
height: 100%;
display: flex;
flex: 1;
}
.left {
width: 180px;
background: #aafed6;
}
.right {
width: auto;
background: #e8f6fe;
}
footer {
width: 100%;
background-color: #000;
color: #fff;
padding: 1em;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
}
View jsfiddle - http://jsfiddle.net/jalenconner/be71229w/1/
This solution utilizes CSS Flexbox, which you can learn more about here: https://css-tricks.com/snippets/css/a-guide-to-flexbox/
html {
position: relative;
height: 100%;
}
body {
height: 100%
}
.container {
/* Full Height - height of footer*/
height: calc(100% - 50px);
display: flex;
flex-direction: row;
}
.left {
width: 20%;
float: left;
background: #aafed6;
height: 100%;
}
.right {
background: #e8f6fe;
width: 80%;
}
footer {
width: 100%;
background-color: #000;
color: #fff;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
height: 50px;
}
.footer-text {
padding: 1em;
}
Just a little tweak to the body tag fixes it
*,
*:after,
*:before {
-moz-box-sizing:border-box;
box-sizing:border-box;
}
html {
position: relative;
height: 100%;
}
body {
height: 100%;
margin: 0;
}
.container {
height: inherit;
overflow: hidden;
}
.left {
width: 180px;
float: left;
background: #aafed6;
height: calc(100% - 50px);/**deduct heght of footer**/
}
.right {
float: none;
/* not needed, just for clarification */
background: #e8f6fe;
/* the next props are meant to keep this block independent from the other
floated one */
width: auto;
overflow: hidden;
}
footer {
width: 100%;
background-color: #000;
color: #fff;
padding: 1em;
position: absolute;
left: 0;
bottom: 0;
width: 100%;
}
<body>
<div class="container">
<div class="left">
left content fixed width
<br>
<br> I want this to extend to footer!
</div>
<div class="right">
right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
<br>
<br> right content flexible width
</div>
</div>
<footer>
This is my footer.
</footer>
</body>
html {
position: relative;
}
body {
margin-bottom: 40px;
}
html, body {
height: 100%;
}
.container {
overflow: auto;
display: flex;
min-height: 100%;
}
.left {
width: 180px;
background: #aafed6;
}
.right {
background: #e8f6fe;
width: auto;
overflow: hidden;
}
footer {
width: 100%;
background-color: #000;
color: #fff;
position: fixed;
left: 0;
bottom: 0;
width: 100%;
height: 40px;
}
Use above CSS code, you will get desired output with fixed footer and content with 100% height.
I'm trying to create a layout for a page like this with a full height left close bar. I keep running into the left close bar either pushing everything down or is limited to only the top left corner:
I think you want something like that.
body {margin:0;}
.side {
position: fixed;
background: blue;
top: 0;
left: 0;
bottom: 0;
width: 100px;
}
.content {
padding-left: 100px;
width: 100%;
height: 100vh;
box-sizing: border-box;
}
.top {
height: 100px;
width: 100%;
background: orange;
float: left;
}
.left, .right {
width: 50%;
height: 200px;
float: left;
}
.left {
background: green;
}
.right {
background: magenta;
}
<div class="side"></div>
<div class="content">
<div class="top"></div>
<div class="left"></div>
<div class="right"></div>
</div>
If you want to make the sidebar full height you can use
.sidebar{
height:100vh;
}
and then you can give position:fixed;
My simple layout contains header, main section and footer. Footer pushed to bottom of a page. And I want main section to take all the space between header and footer. Here is what I've done: http://jsfiddle.net/5d3m9/
HTML
<div class="wrap">
<header>header</header>
<div class="main">lorem2000 </div>
<div class="clear"></div>
<footer>#Copyright</footer>
</div>
CSS
html, body {
height: 100%;
}
body {
margin: 0;
}
header {
height: 150px;
background: orange;
}
.wrap {
min-height: 100%;
position: relative;
overflow: hidden;
}
.main {
background: #00eaea;
padding-bottom: 32767px;
margin-bottom: -32767px;
}
.clear {
height: 50px;
}
footer {
background: #dadada;
height: 50px;
width: 100%;
position: absolute;
bottom: 0;
}
Is there any other/better way to achieve this? (without padding-bottom: 32767px; margin-bottom: -32767px;)
Apply the following style to .main
.main {
background: #00eaea;
top: 150px;
bottom: 50px;
position:absolute;
width: 100%;
}
http://jsfiddle.net/5d3m9/1/