CSS Layering Divs - css

I want 100% wide divs containing images to go down my page.
On top of these divs, I want one 1210px wide div where I can put my content.
Example:
http://mudchallenger.com/a-responsivee.html
Question:
How can I get the blue box to touch the green box, while red box stays above the two?
Thank you!
I currently have this:
}
#green{
position: absolute;
float:center;
height: 500px;
width: 100%;
margin: 0 auto;
z-index:1;
background-color: green;
}
#blue{
position: relative;
float:center;
height: 500px;
width: 100%;
margin: 0 auto;
z-index:1;
background-color: blue;
}
#red{
position: relative;
float:center;
height: 800px;
width: 1210px;
margin: 0 auto;
z-index:2;
background-color: red;
}

Use background-images to accomplish what you want. Just stack your divs and it should work just fine. If you want your content to span two containers with background images, that's a different story, but the example you cite doesn't do that.
Here's a fiddle giving close to an implementation of what you want. Just replace the container background-colors with background-images and you'd have what you want.
http://jsfiddle.net/CfZu4/
HTML:
<div class="container">
<div class="content">
Blah
</div>
</div>
<div class="container red">
<div class="content">
Blah
</div>
</div>
CSS:
.container{
background-color:#00f;
height:200px;
clear:both;
}
.content{
float:right;
width:40%;
height:150px;
margin-top:20px;
background-color:#0f0;
}
.red{
background-color:#f00;
}

EDIT: Scaled down version for fiddle:
http://jsfiddle.net/dc2bar/asy8Y/2/
HTML:
<div class="background-banner green">
<div class="main-content red">
<!-- content -->
</div>
</div>
<div class="background-banner blue">
</div>
CSS:
.background-banner {
height: 500px;
width: 100%;
margin: 0 auto;
z-index:1;
}
.main-content {
position: relative;
height: 800px;
width: 70%;
margin: 0 auto;
z-index:2;
}
.green{
background-color: green;
}
.blue{
background-color: blue;
}
.red{
background-color: red;
}
EDIT yet again: removed invalid css rule.

Related

div table-responsive image

I created a div based table. I'm trying to take a image, put it in top left table cell and make it responsive. I've made it responsive, but its not in the table cell I want it to be. Any help?
JSFiddle:
https://jsfiddle.net/benjones337/3c4fkb78/18/
HTML
<div class="hmTable">
<div class="hmTableRow">
<div class="hmTableCell"><p class="rspimg1"></p></div>
<div class="hmTableCell"><p class="rspimg2"></p></div>
</div>
<div class="hmTableRow">
<div class="hmTableCell">textholder</div>
<div class="hmTableCell">textholder</div>
</div>
</div>
CSS
.hmTable {
margin: 0 auto; /* or margin: 0 auto 0 auto */
display: table;
width: 50%;
}
.hmTableRow {
display: table-row;
}
.hmTableCell, .hmTableHead {
display: table-cell;
width: 50%;
height:100%;
border: 1px solid #999999;
position:relative;
}
.hmTableBody {
display: table-row-group;
}
.rspimg1{
background-image: url("https://upload.wikimedia.org/wikipedia/en/thumb/3/39/Red_triangle_with_thick_white_border.svg/1152px-Red_triangle_with_thick_white_border.svg.png");
background-repeat:no-repeat;
background-size:100% 100%;
width:100%;
height:100%;
position:absolute;
}
.rspnimg2{
}
When using background-image, the div doesn't grow with the image, so you will need to give it a height/width, either to the cell or the image div (btw, I changed your p to div, as p is for text rather than image).
Below sample I'm pretty sure look close to what you are after, and If not, drop me a comment and I'll fix it for you.
html, body {
margin: 0;
height: 100%;
}
.hmTable {
margin: 0 auto;
display: table;
width: 50%;
height: 30%;
}
.hmTableRow {
display: table-row;
height: 10%;
}
.hmTableCell, .hmTableHead {
display: table-cell;
width: 50%;
height:100%;
border: 1px solid #999999;
}
.rspimg1{
background: url("https://upload.wikimedia.org/wikipedia/en/thumb/3/39/Red_triangle_with_thick_white_border.svg/1152px-Red_triangle_with_thick_white_border.svg.png") center no-repeat;
background-size: contain;
width:100%;
height:100%;
}
.rspnimg2{
}
<div class="hmTable">
<div class="hmTableRow">
<div class="hmTableCell">
<div class="rspimg1">triangle</div>
</div>
<div class="hmTableCell">
<div class="rspimg2">square</div>
</div>
</div>
<div class="hmTableRow">
<div class="hmTableCell">textholder</div>
<div class="hmTableCell">textholder</div>
</div>
</div>
Remove position:absolute or add top:0 to .rspimg1.
Result

two column layout, content first

HTML:
<div id="main">
<div id="sidebar"></div>
<div id="content"></div>
</div>
CSS:
#content {
background: blue;
height: 900px;
}
#sidebar {
float: left;
width: 200px;
height: 900px;
background: red
}
JSFIDDLE: http://jsfiddle.net/aFrPc/
While this works, I would like to have #content listed first (instead of #sidebar).
Div #content must fill all remaining space.
Image of final wanted result:
UPDATED If he wants the content text before the sidenav text.
Fiddle
<div id="main">
<div id="content">
<div style="padding-left:200px">
Context
</div>
</div>
<div id="sidebar">sidebar</div>
</div><!--#main-->
#content {
background: blue;
height: 900px;
width:100%;
margin-left:-200px;
float:right;
color:#fff;
}
#sidebar {
float: left;
width: 200px;
height: 900px;
background: red;
}
Try this. #Content is listed first, and takes up 100% of the remaining space after a 200px sidebar:
body{
overflow-x:hidden;
}
#content {
background: blue;
height: 900px;
position:absolute;
width:100%;
left:200px;
}
#sidebar {
float: left;
width: 200px;
height: 900px;
background: red
}
Jsfiddle: http://jsfiddle.net/VkQ6U/

Aligning five divs next to each other

I'm currently making a website where you can find results of Formula One races. To do so, I want to make a result page for each Grand Prix, where the results are being shown in 5 boxes next to each other. Like this:
1 2 3 4 5
But right now it looks like this
1 2
3
4 5
This is the HTML code I use:
<div id="wrap">
<div id="fp1">FP1</div>
<div id="fp2">FP2</div>
<div id="fp3">FP3</div>
<div id="qual">Qual</div>
<div id="race">Race</div>
</div> <!--End wrap div-->
And this the CSS I use:
#wrap{
width: 100%;
height: 600px;
background-color: #000;
border: 1px solid white;
}
#fp1{
width: 20%;
height: 600px;
background-color: #333;
float: left;
}
#fp2{
margin-left: 20%;
width: 20%;
height: 600px;
background-color: #666;
}
#fp3{
margin-left: 40%;
width: 20%;
height: 600px;
background-color: #333;
}
#qual{
margin-left: 60%;
width: 20%;
height: 600px;
background-color: #666;
float: right;
}
#race{
width: 20%;
height: 600px;
background-color: #333;
float: right;
}
Anybody who knows how to fix it?
please check this: http://jsfiddle.net/itz2k13/KAwEz/
#fp1{
width: 20%;
height: 600px;
background-color: #333;
float: left;
}
.....
You can use a generic class, since styles are repetitive. see this for efficient one: http://jsfiddle.net/itz2k13/KAwEz/1/
else you can follow inline-block method, and further in time column and display:flex will be usefull:
http://codepen.io/seraphzz/pen/IosFk
#wrap {
white-space:nowrap;
}
#wrap, .wrap {
/* for test */
height:200px;
overflow:auto;}
.wrap {
-moz-column-width:300px;
-webkit-column-width:300px;
column-width:300px;
}
#wrap div {
white-space:normal;
display:inline-block;
}
#wrap div , .wrap div {
/* for test */
width:300px;
height:100%;
background:#999;
}
<div id="wrap">
<div id="fp1">FP1</div>
<div id="fp2">FP2</div>
<div id="fp3">FP3</div>
<div id="qual">Qual</div>
<div id="race">Race</div>
</div> <!--End wrap div-->
<div class="wrap" >
<div id="fp1">FP1</div>
<div id="fp2">FP2</div>
<div id="fp3">FP3</div>
<div id="qual">Qual</div>
<div id="race">Race</div>
</div> <!--End wrap div-->
If you want no scroll, divide 100%/numbers of boxes (fine if window not too small :) )
cheers
One more thing i noticed other than float:left regarding structure is you can use margin-left without % and give common margin-left like 20px

3 row CSS div design

I am trying to make 3 div's in row design. Where the header and footer have fixed height.
The center div expands to fill the empty space. I have tried but the closest I got is the code below. Still having problems with the center div which expands over the footer div.
html:
<div id='container'>
<div id='rowOne'>row 1</div>
<div id='rowTwo'>row 2</div>
<div id='rowThree'>row 3</div>
</div>
css:
#rowOne {
width: 100%;
height: 50px;
background: green;
}
#rowTwo {
width: 100%;
background: limegreen;
height:100%;
overflow:hidden;
}
#rowThree {
width: 100%;
position: fixed;
clear: both;
background: green;
position:absolute;
bottom:0;
left:0;
height:50px;
}
#container {
height: 100%;
}
Three Row pure CSS
I know this post is getting on a bit, but despite claims to the contrary, you can do this very simply with CSS. No need for JavaScript, jQuery, CSS 3 hacks etc.
Here's a couple of jsf's that show fixed header and footer and dynamic body div.
This first one shows fixed pixel height header and footer and dynamic body EXACTLY as you wanted in your image
http://jsfiddle.net/LBQ7K/
<body>
<div class="header"><p>Header</p></div>
<div class="cssBody"><p>Hello World</p></div>
<div class="footer"><p>Footer</p></div>
</body>
html, body, {
height: 100%;
}
.header {
position: absolute;
top: 0px;
height: 50px;
width: 100%;
background: #f00;
}
.footer {
position: absolute;
bottom: 0;
height: 50px;
width: 100%;
background: #00f;
}
.cssBody {
position: absolute;
top: 50px;
bottom: 50px;
width: 100%;
background: #0f0;
}
The second shows you can use the same technique to have dynamic headers & footers.
http://jsfiddle.net/reqXJ/
<body>
<div class="header"><p>Header</p></div>
<div class="cssBody"><p>Hello World</p></div>
<div class="footer"><p>Footer</p></div>
</body>
html, body, {
height: 100%;
}
.header {
position: absolute;
top: 0px;
height: 15%;
width: 100%;
background: #f00;
}
.footer {
position: absolute;
bottom: 0;
height: 15%;
width: 100%;
background: #00f;
}
.cssBody {
position: absolute;
top: 15%;
bottom: 15%;
width: 100%;
background: #0f0;
}
This is a very common problem, one of the solutions that worked for me is from the following website:
http://ryanfait.com/sticky-footer/
with the code:
http://ryanfait.com/sticky-footer/layout.css
and another popular choice:
http://www.cssstickyfooter.com/
If this does not meet your needs, let us know, we can help more.
Seems like you are try to do a sticky footer, well... you will need a few hacks:
HTML:
<div id='container'>
<div class="header">
<h1>Sticky Footer!</h1>
</div>
<div id='rowOne'>row 1</div>
<div id='rowTwo'>row 2</div>
<div id='rowThree'>row 3</div>
<div class="push"></div>
</div>
<div id='footer'></div>
CSS
.container {
min-height: 100%;
height: auto !important;height: 100%;
/* the bottom margin is the negative value of the footer's height */
margin: 0 auto -142px;
}
.footer, .push{
height: 142px; /* .push must be the same height as .footer */
}
Note: Replace the footer and push height for your fixed height and don't forget to insert the push div after the rows in the container.
You can fake this by absolutely positioning the rows, and adding padding to top and bottom for the middle row. You cannot do this like you were doing with tables
#container { position:relative; height:800px } // needs height
#rowOne, #rowTwo, #rowThree { position:absolute }
#rowOne { top:0; left:0 }
#rowThree { bottom:0; left:0 }
#rowTwo { left:0; top:0; padding:50px 0; } // top and bottom padding 50px
could this line of code help?
DEMO
Try this:
#container{
...
position:relative;
}
#content{
min-height: xxx;
}
This should exactly do what you want:
html code:
<div id="header">
header
</div>
<div id='container'>
<div id='rowOne'>one</div>
<div id='rowTwo'>two</div>
<div id='rowThree'>three</div>
</div>
<div class="clearfix"></div>
<div id="footer">
footer
</div>
CSS code:
.clearfix {
clear: both;
}
#header, #footer {
background-color: red;
}
#container {
width: 100%;
}
#rowOne {
width: 25%;
background: green;
float: left;
}
#rowTwo {
width: 55%;
height: 100px;
background: limegreen;
float: left;
}
#rowThree {
width: 20%;
background: green;
float: left;
}​
You can also test it on jsFiddle
Have you tried looking at a CSS framework? They come with default classes you can use to set up something like that within a few short minutes. They also help producing cleaner html and interfaces that you can easily redesign at a later time.
http://twitter.github.com/bootstrap/index.html
I hope you are looking like this :- DEMO
CSS
#container {
height: 100%;
}
#rowOne {
height: 50px;
background: green;
position:fixed;
left:0;
right:0;
}
#rowTwo {
background: limegreen;
min-height:500px;
position:absolute;
left:0;
right:0;
top:50px;
}
#rowThree {
position: fixed;
background: green;
bottom:0;
left:0;
right:0;
height:50px;
}
HTML
<div id='container'>
<div id='rowOne'>row 1</div>
<div id='rowTwo'>row 2</div>
<div id='rowThree'>row 3</div>
</div>
In response to your comment on jedrus07's answer:
all this sollutions expand the center div behind the footer div. I want a solution with each div having only his own space.
The only way to do that is with CSS 3 calc(). If you don't need to support very many browsers, that's an option, and here's a demo of it in action:
http://jsfiddle.net/5QGgZ/3/
(Use Chrome or Safari.)
HTML:
<html>
<body>
<div id='container'>
<div id='rowOne'>row 1</div>
<div id='rowTwo'>row 2</div>
<div id='rowThree'>row 3</div>
</div>
</body>
</html>
CSS:
html, body, #container {
height: 100%;
}
#rowOne {
height: 50px;
background: #f00;
}
#rowTwo {
height: -webkit-calc(100% - 100px);
background: #0f0;
}
#rowThree {
height: 50px;
background: #00f;
}
If you want wider browser support, you're going to have to go with a sticky footer solution like the ones jedrus07 mentioned, or Tom Sarduy's answer.
One way would be using Jquery to set the minimum height of the middle div to be the height of the screen, minus the height of the other two divs (100px)
something like this should work:
$(document).ready(function() {
var screenHeight = $(document).height() - 100px;
$('#rowTwo').css('min-height' , screenHeight);
});

2 divs position

Again me with my divs =(.
I have this:
<div id="header"></div>
<div id="body">
<div id="..."></div>
<div id="..."></div>
<div id="content"></div>
</div>
<div id="footer"></div>
and css:
#body { width: 100%; margin 0 auto; }
#content { position: absolute; height: 200px; width: 100%; }
#footer { height: 63px; clear:both; }
Now result:
content div with much text and footer under text.
How can I make my footer under all content-area?
I've encountered this situation several times. I've been using sticky footers. It's widely compatible with several browsers and just seems to work.
If you use this styling you will see the (blue) #footer under the (red) #content as you requested:
#body {width: 600px; margin 0 auto; }
#content {position: relative; height: 200px; width: 600px; background-color: red; }
#footer {height: 63px; clear:both; width: 600px; background-color: blue; }

Resources