An issue with nested divs - css

I'm sure there's a simple solution to this, but I've been beating my head up against it for an hour or two and not making much progress.
Basically, I've got a wrapper div (testwrap_outer) containing a secondary wrapper div (testwrap_inner) that holds together an image thumbnail div (test1), and a caption div (test2).
I need the caption div (test2) to scale height according to its content, the secondary wrapper (testwrap_inner) to contain that div and float next to any other secondary wrapper divs, and the main wrapper (testwrap_outer) to contain all of them.
I apologize for doing such a poor job explaining, so I've provided a picture to illustrate what I mean here. Here is a fiddle.
HTML
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi congue mi at aliquet blandit. Praesent tristique, dui sit amet iaculis mollis, nunc elit semper nisi, vitae finibus nulla dui in enim. In lacinia aliquam tempus. Nunc sollicitudin ac massa non porttitor. Maecenas quam urna, semper ut mauris id, lacinia consequat libero. Vivamus neque diam, vestibulum a est eget, aliquam tempus magna. Morbi sed tellus lobortis, condimentum mi id, finibus felis.</p>
<div class=testwrap_outer>
<div class=testwrap_inner>
<!-- THUMBNAIL IMAGE -->
<div class=test1>
<img src="http://i.imgur.com/5KObDyq.jpg">
</div>
<!-- THUMBNAIL CAPTION -->
<div class=test2><b>TEST2</b>
<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi congue mi at aliquet blandit. Praesent tristique, dui sit amet iaculis mollis, nunc elit semper nisi, vitae finibus nulla dui in enim.</div>
</div>
<div class=testwrap_inner>
<!-- THUMBNAIL IMAGE -->
<div class=test1>
<img src="http://i.imgur.com/5KObDyq.jpg">
</div>
<!-- THUMBNAIL CAPTION -->
<div class=test2><b>TEST2</b>
<br>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi congue mi at aliquet blandit. Praesent tristique, dui sit amet iaculis mollis, nunc elit semper nisi, vitae finibus nulla dui in enim.</div>
</div>
</div>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi congue mi at aliquet blandit. Praesent tristique, dui sit amet iaculis mollis, nunc elit semper nisi, vitae finibus nulla dui in enim. In lacinia aliquam tempus. Nunc sollicitudin ac massa non porttitor. Maecenas quam urna, semper ut mauris id, lacinia consequat libero. Vivamus neque diam, vestibulum a est eget, aliquam tempus magna. Morbi sed tellus lobortis, condimentum mi id, finibus felis.</p>
CSS
body {
background: #cccccc;
font-family: Arial, Helvetica, sans-serif;
min-width: 900px;
}
.testwrap_outer {
border: 1px solid red;
position: relative;
}
.testwrap_inner {
border: 1px solid blue;
float: left;
margin: 5px;
padding: 4px;
width: 296px;
}
.test1 {
border: 1px solid purple;
position: relative;
float: left;
opacity: 1.0;
width: 80px;
height: 80px;
overflow: hidden
}
.test1 img {
height: 100%;
}
.test1 img:hover {
opacity: 0.6;
}
.test2 {
border: 0px solid green;
position: relative;
float: left;
text-align: justify;
text-justify: inter-word;
padding: 6px;
width: 200px;
}
Any help is much appreciated.

Add inside testwrap_outer an empty div with clear:both style. This will tidy up the layout and make the outer div behave as a container supposed to be behave.
Updated fiddle:
http://jsfiddle.net/a3hz8dss/1/

just include overflow:hidden in your class testwrap_outer, also there is no need of position:relative in your code!!
CSS:
.testwrap_outer{
border: 1px solid red;
overflow:hidden;
}
Fiddle Demo

Related

Make element sticky from certain height

I am trying to make the following element (which is back to top link) appear just from a certain height.
As it for now it is always displayed and I would like to appear after some scrolling or even after a fixed size.
I would like to do it with CSS only if possible.
<div style='z-index: 9999; bottom: 3em; right: 3em; position: sticky; width: 32px; text-align: center'>
<a href='#top'>
<i class='fas fa-chevron-up fa-2x'/>
</a>
</div>
Thanks
You can approximate like below
.box {
position:absolute;
display:flex;
top:600px; /* the height you want here*/
left:0;
right:0;
bottom:0;
pointer-events:none;
}
.box a {
position: sticky;
z-index:999;
margin:auto 3em 3em auto;
bottom: 3em;
border-radius: 50%;
background: black;
color: #fff;
padding: 5px 7px;
font-size:16px;
pointer-events:initial;
}
body {
font-size:50px;
position:relative;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus consectetur ultrices arcu viverra malesuada. Donec pulvinar luctus lorem, eu consectetur felis interdum et. Nullam libero sem, aliquet eu porttitor ac, ullamcorper eget purus. Quisque tempus diam lorem, in aliquet arcu ullamcorper ut. Pellentesque non commodo tortor. Sed malesuada augue pellentesque diam aliquet, sit amet rhoncus diam mollis. Fusce justo leo, finibus eu turpis sit amet, ultrices condimentum mi. Duis at ornare eros, id venenatis neque. Aliquam blandit hendrerit tempus. Curabitur suscipit ipsum nec accumsan placerat.
<div class="box" >
<a href='#top'>
<i class='fas fa-chevron-up fa-2x'></i>
</a>
</div>
You can also consider a mask trick to hide the element when it's not needed (there is no scroll on the page)
.box {
position:absolute;
display:flex;
top:600px; /* the height you want here*/
left:0;
right:0;
bottom:0;
pointer-events:none;
-webkit-mask:linear-gradient(transparent calc(100vh - 600px),#fff 0);
}
.box a {
position: sticky;
z-index:999;
margin:auto 3em 3em auto;
bottom: 3em;
border-radius: 50%;
background: black;
color: #fff;
padding: 5px 7px;
font-size:16px;
pointer-events:initial;
}
body {
font-size:50px;
position:relative;
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus consectetur ultrices arcu viverra malesuada. Donec pulvinar luctus lorem, eu consectetur felis interdum et. Nullam libero sem, aliquet eu porttitor ac, ullamcorper eget purus. Quisque tempus diam lorem, in aliquet arcu ullamcorper ut. Pellentesque non commodo tortor. Sed malesuada augue pellentesque diam aliquet, sit amet rhoncus diam mollis. Fusce justo leo, finibus eu turpis sit amet, ultrices condimentum mi. Duis at ornare eros, id venenatis neque. Aliquam blandit hendrerit tempus. Curabitur suscipit ipsum nec accumsan placerat.
<div class="box" >
<a href='#top'>
<i class='fas fa-chevron-up fa-2x'></i>
</a>
</div>

Linear gradient which make text "disappear"

I need some help.
There are a few containers that have text inside. Obviously there is a lot of text, so there have to be scroll. But I don't want text look like it's cut, I want to "blur" the bottom of the single container.
Here are the results: https://jsfiddle.net/rsze93wk/3/
Well, it looks... pretty shitty in my opinion. The bottom of the container should be almost invisible, but I can clearly read it. I used :after and display: block to make this effect, so I'm unable to select the text under that pseudo-element.
There is also a problem, gradient stays in one place when I scroll down. Can you help me solve this? Also, maybe you have any ideas how to make this effect look much better?
Update: the first snippet seems to be buggy on Chrome but works fine on Firefox
You can try to color the text using gradient like below:
body {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
margin: 0;
height: 100vh;
}
.container {
padding: 20px;
border: 1px solid black;
}
.main:not(:first-child) {
margin-top: 20px;
}
.main {
width: 200px;
height: 200px;
box-shadow: 0px 0px 20px 1px rgba(0,0,0,0.75);
overflow: auto;
text-align: center;
background: linear-gradient(#000 calc(100% - 50px),white);
-webkit-background-clip:text;
background-clip:text;
color:transparent;
}
<div class="container">
<div class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ex massa, vestibulum non quam quis, commodo fermentum purus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in erat libero. Phasellus ipsum odio, rutrum porttitor velit a, venenatis cursus nisi. Donec venenatis, felis at luctus ullamcorper, leo nibh scelerisque orci, et pellentesque quam libero vel enim. Pellentesque a mauris nibh. Suspendisse eu laoreet nisi. Pellentesque bibendum ullamcorper iaculis. Nulla tortor odio, vehicula ac diam non, aliquet tristique sem.</p>
</div>
<div class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ex massa, vestibulum non quam quis, commodo fermentum purus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in erat libero. Phasellus ipsum odio, rutrum porttitor velit a, venenatis cursus nisi. Donec venenatis, felis at luctus ullamcorper, leo nibh scelerisque orci, et pellentesque quam libero vel enim. Pellentesque a mauris nibh. Suspendisse eu laoreet nisi. Pellentesque bibendum ullamcorper iaculis. Nulla tortor odio, vehicula ac diam non, aliquet tristique sem.</p>
</div>
</div>
Another alternative using sticky:
body {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
margin: 0;
height: 100vh;
}
.container {
padding: 20px;
border: 1px solid black;
}
.main:not(:first-child) {
margin-top: 20px;
}
.main {
width: 200px;
height: 200px;
box-shadow: 0px 0px 20px 1px rgba(0,0,0,0.75);
overflow: auto;
text-align: center;
}
.main::after {
content:"";
display:block;
height:200px;
margin-top:-200px;
position:sticky;
bottom:0;
background: linear-gradient(transparent calc(100% - 50px),white);
pointer-events:none;
}
<div class="container">
<div class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ex massa, vestibulum non quam quis, commodo fermentum purus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in erat libero. Phasellus ipsum odio, rutrum porttitor velit a, venenatis cursus nisi. Donec venenatis, felis at luctus ullamcorper, leo nibh scelerisque orci, et pellentesque quam libero vel enim. Pellentesque a mauris nibh. Suspendisse eu laoreet nisi. Pellentesque bibendum ullamcorper iaculis. Nulla tortor odio, vehicula ac diam non, aliquet tristique sem.</p>
</div>
<div class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ex massa, vestibulum non quam quis, commodo fermentum purus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in erat libero. Phasellus ipsum odio, rutrum porttitor velit a, venenatis cursus nisi. Donec venenatis, felis at luctus ullamcorper, leo nibh scelerisque orci, et pellentesque quam libero vel enim. Pellentesque a mauris nibh. Suspendisse eu laoreet nisi. Pellentesque bibendum ullamcorper iaculis. Nulla tortor odio, vehicula ac diam non, aliquet tristique sem.</p>
</div>
</div>
And if you want a real blur effect use backdrop-filter:
body {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
margin: 0;
height: 100vh;
}
.container {
padding: 20px;
border: 1px solid black;
}
.main:not(:first-child) {
margin-top: 20px;
}
.main {
width: 200px;
height: 200px;
box-shadow: 0px 0px 20px 1px rgba(0,0,0,0.75);
overflow: auto;
text-align: center;
}
.main::after {
content:"";
display:block;
height:20px;
margin-top:20px;
position:sticky;
bottom:0;
pointer-events:none;
-webkit-backdrop-filter:blur(5px);
backdrop-filter:blur(5px);
}
<div class="container">
<div class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ex massa, vestibulum non quam quis, commodo fermentum purus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in erat libero. Phasellus ipsum odio, rutrum porttitor velit a, venenatis cursus nisi. Donec venenatis, felis at luctus ullamcorper, leo nibh scelerisque orci, et pellentesque quam libero vel enim. Pellentesque a mauris nibh. Suspendisse eu laoreet nisi. Pellentesque bibendum ullamcorper iaculis. Nulla tortor odio, vehicula ac diam non, aliquet tristique sem.</p>
</div>
<div class="main">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ex massa, vestibulum non quam quis, commodo fermentum purus. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in erat libero. Phasellus ipsum odio, rutrum porttitor velit a, venenatis cursus nisi. Donec venenatis, felis at luctus ullamcorper, leo nibh scelerisque orci, et pellentesque quam libero vel enim. Pellentesque a mauris nibh. Suspendisse eu laoreet nisi. Pellentesque bibendum ullamcorper iaculis. Nulla tortor odio, vehicula ac diam non, aliquet tristique sem.</p>
</div>
</div>
I want to "blur" the bottom of the single container.
Blur is CSS filter (filter: blur(1)) and you can't use it here with the after:: pseudoelement because content of that element is empty.
I used :after and display: block to make this effect, so I'm unable to select the text under that pseudo-element.
This is a good and common solution. To make text bellow the after:: clickable you can add pointer-events: none; to the after::.
There is also a problem, gradient stays in one place when I scroll down.
after:: should be positioned to the .main and in the .main you should have another container with scroll.

What in my CS code is making my right column drop down when with smaller screen size?

When I resize my window to 1280 x 720 or below I just realized I'm getting some behavior I do not want. The right column (.right class) is getting "bumped down" below when I resize my window
What is it in my CSS code (or not in the code) that's causing this? I have a feeling that I'm missing a very important concept here. :)
Here is what happens to the right column on smaller screens: http://s11.postimg.org/vp9c7o3dv/css.png
And here is the faulty code:
http://codepen.io/cosmonaut/pen/yyvZjZ?editors=110
html {
background: url(http://s16.postimg.org/k5re12691/bg_radium.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
body {
width: 95%;
font-family: courier;
font-size: 15px;
color: #E7DFC2;
margin-left: 30px;
}
.container {
width: 90%;
margin: 10px auto;
background-color: #273E23;
opacity: 0.97;
margin-top: 25px;
}
.header {
text-align:center;
font-size: 40px;
padding: 1em;
border-bottom: 1px solid gray; /* Temporary. */
background-color: #273E23;
}
.header p {
font-size: 25px;
padding: 0px;
margin: 0px;
background-color: #273E23;
}
.header img {
padding: 0px;
margin: 0px;
width: 200px;
height: 200px;
}
.menu {
text-align: center;
}
.menu ul {
}
.menu ul li {
margin: 0 20px;
padding: 0;
list-style-type: none;
display: inline-block;
}
.menu ul li a {
text-decoration: none;
background-color: #273E23;
color: #D3B474;
}
.left {
float: left;
width: 160px;
margin: 0;
padding: 1em;
}
.right {
padding: 1em;
float: right;
width: 860px;
background-color: #273E23;;
}
.right p {
background-color: #273E23;
}
.footer {
clear: both;
margin: 0px;
padding: .5em;
text-align: center;
background-color: #273E23;
}
<!DOCTYPE html>
<html>
<head>
<link type="text/css" rel="stylesheet" href="stylesheet_v2.css"/>
<title>Radium Recordings</title>
</head>
<body>
<div class="container">
<div class="header">
<img src="http://s11.postimg.org/z08mz7o9f/radium4.png">
</div>
<div class="menu">
<ul>
<li>Home</li>
<li>Releases</li>
<li>Tours</li>
<li>Contact</li>
</ul>
</div>
<div class="left"><p>Hi, I'm the left side. Not sure if I'm even going to keep this column. Lorem Ipsum added:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia tellus vel nunc accumsan maximus. Pellentesque justo sem, condimentum non lectus sed, consequat dignissim eros. Integer id ante lectus. Nam id nisi dui. Curabitur euismod volutpat accumsan. Donec pellentesque metus eleifend, imperdiet arcu lacinia, convallis est. Curabitur porta interdum vehicula. Fusce mollis quam et ex venenatis, eget luctus risus pellentesque.</p>
</div>
<div class="right">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia tellus vel nunc accumsan maximus. Pellentesque justo sem, condimentum non lectus sed, consequat dignissim eros. Integer id ante lectus. Nam id nisi dui. Curabitur euismod volutpat accumsan. Donec pellentesque metus eleifend, imperdiet arcu lacinia, convallis est. Curabitur porta interdum vehicula. Fusce mollis quam et ex venenatis, eget luctus risus pellentesque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia tellus vel nunc accumsan maximus. Pellentesque justo sem, condimentum non lectus sed, consequat dignissim eros. Integer id ante lectus. Nam id nisi dui. Curabitur euismod volutpat accumsan. Donec pellentesque metus eleifend, imperdiet arcu lacinia, convallis est. Curabitur porta interdum vehicula. Fusce mollis quam et ex venenatis, eget luctus risus pellentesque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia tellus vel nunc accumsan maximus. Pellentesque justo sem, condimentum non lectus sed, consequat dignissim eros. Integer id ante lectus. Nam id nisi dui. Curabitur euismod volutpat accumsan. Donec pellentesque metus eleifend, imperdiet arcu lacinia, convallis est. Curabitur porta interdum vehicula. Fusce mollis quam et ex venenatis, eget luctus risus pellentesque.</p>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris lacinia tellus vel nunc accumsan maximus. Pellentesque justo sem, condimentum non lectus sed, consequat dignissim eros. Integer id ante lectus. Nam id nisi dui. Curabitur euismod volutpat accumsan. Donec pellentesque metus eleifend, imperdiet arcu lacinia, convallis est. Curabitur porta interdum vehicula. Fusce mollis quam et ex venenatis, eget luctus risus pellentesque.</p>
<p>Aliquam convallis nulla commodo convallis scelerisque. Curabitur elementum porttitor purus, posuere tincidunt turpis sagittis et. Proin non nulla vitae velit rutrum egestas id vitae dolor. Mauris placerat nec metus vel ultrices. Integer molestie lobortis eros a dapibus. Pellentesque commodo iaculis magna fringilla rhoncus. Nullam luctus dui elit, nec ornare erat volutpat vitae. Vestibulum nulla velit, porttitor in hendrerit vel, varius sit amet elit. Aliquam erat volutpat.
</p>
</div>
<div class="footer">
<p>P.O. Box 321, Anywhere, USA 31721 | Tel: (888) 888-8888</p>
</div>
</div>
</body>
</html>
Change your column widths to percentages. One example is this Codepen.
I used:
.left {
float: left;
width: 20%;
margin: 0;
padding: 1em;
}
.right {
padding: 1em;
float: right;
width: 67%;
background-color: #273E23;;
}
but you can use any percentages that look right to you.
You have two column in your site. One have class name "left" another have class named "right". Now each of those class have fixed width. So when the screen size goes less than the declared width the 2nd column get down to get it desire size.
If we see the explanation:
.right {
padding: 1em;
float: right;
width: 860px;
background-color: #273E23;
}
.left {
float: left;
width: 160px;
margin: 0;
padding: 1em;
}
Here we can see right class have width of 860px and the left class have width of 160px. Also the right class have a padding of 1em which is 15 in pixel. So if you want to show both of the element in single line then the minimum screen size should be 1050px (860 + 30 + 160). Here 30 is summation of both side padding 15 px.
If you want to do the code in such way that you what ever the screen size is both column should maintain size ratio then instead of using fixed width you should use %. For batter understanding you can check example of #bobdye
On small screen you have not enough space in .container for two columns.
You should set .container width in px, or declare min-width for it, or declare width of left and right columns in %.

Maintain text on right side of image after clear both using CSS

Using HTML and CSS I'm trying to display a news feed where there are an image, a title a date and the text itself.
In the below image, the first group is the actual result, the second one is the result I'm trying to achieve.
And here's the code:
HTML
<div class="news_block">
<div>
<img src="images/facebook.png">
<p class="title_news_tit"><strong>Title</strong></p>
<p class="title_news_date"><strong>21-21-2013</strong></p>
<p class="title_news_testo">Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Morbi tempus porttitor elit. Nulla pretium sapien vel neque iaculis,
eu tempus dui dapibus. Ut rhoncus vestibulum dignissim.
Morbi convallis ligula ultrices, imperdiet est ac, iaculis ligula.
Pellentesque elementum, enim quis cursus varius, lectus nulla gravida nisl,
vel rutrum nisl leo tempor metus. Sed at feugiat eros. Vivamus tincidunt mauris
ultricies justo feugiat, in ultricies sem venenatis. Etiam sodales leo in iaculis facilisis.</p>
</div>
<div class="clear"></div>
</div>
CSS
.news_block {
margin: 20px;
padding: 10px;
min-height: 200px;
background: #F5F5F5;
}
.news_block img {
float: left;
padding: 20px;
}
.title_news_testo
{
float: left;
}
.title_news_tit
{
float: left;
}
.title_news_date
{
float: right;
}
.clear
{
clear: both;
}
EDIT
I made a mistake on the image I uploaded.. in the expected result I want the title aligned to the left and the date to the right.
To much of markup has been used by you, cleaned it up and works well in this way : DEMO
General tip : apply the vertical align to the image to align it always
CSS
.news_block {
margin: 20px;
padding: 10px;
min-height: 200px;
background: #F5F5F5;
}
.news_block img {
float: left;
padding-right:15px;
}
.title_news_date {
float:right;
}
HTML
<div class="news_block">
<img src="http://678ielts.com/wp-content/uploads/2012/11/facebooklogo-200x200.gif" style="width:100px;height:100px;vertical-align:middle">
<div class="text">
<p> <span class="title_news_tit"><strong>Title</strong></span>
<span class="title_news_date"><strong>21-21-2013</strong></span>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi tempus porttitor elit. Nulla pretium sapien vel neque iaculis, eu tempus dui dapibus. Ut rhoncus vestibulum dignissim. Morbi convallis ligula ultrices, imperdiet est ac, iaculis ligula. Pellentesque elementum, enim quis cursus varius, lectus nulla gravida nisl, vel rutrum nisl leo tempor metus. Sed at feugiat eros. Vivamus tincidunt mauris ultricies justo feugiat, in ultricies sem venenatis. Etiam sodales leo in iaculis facilisis.</p>
</div>
</div>
Here is how you can do this on fiddle: http://jsfiddle.net/dZ2kX/2/
There was no need to float everything left
.news_block {
margin: 20px;
padding: 10px;
min-height: 200px;
background: #F5F5F5;
}
.news_block img {
padding: 20px;
background:blue;
width:90px;
height:90px;
float:left;
margin:0 20px 10px 0;
}

div aside with position absolute and sticky footer

I'm in trouble with the following html layout.
I know that there are other questions about absolute positioning and sticky footer, I tried a lot of solutions but I didn't make this work, so I tried to post the whole layout html code to see if someone can find a solution.
I used this StickyFooter solution.
The problem is the right bar.
It shoud stay fixed at 25px from the footer, but, as you see, if the bar content grows, the content goes down over the footer and outside the bar bottom border.
Obviously I would the content stay inside the bar, causing the bar to grown and pushing the footer down.
<!doctype html>
<head>
<style type="text/css">
/* Sticky Footer */
{ margin: 0; }
html, body, form { height: 100%; }
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -50px; /* the bottom margin is the negative value of the footer's height */
}
#footerPage, #divPush
{
height: 50px; /* .push must be the same height as .footer */
}
/* End / Sticky Footer */
body { background-color:#000; width:960px; margin:0 auto; position:relative; font-family:Tahoma, Verdana; }
div.wrapper { background-color:#fff; position:relative; }
#headerPage { }
#divHeaderImg { height:100px; }
#navPage { height:30px; line-height: 30px; font-size:16px; background-color:#90bfe7; padding:0 10px; position:relative; overflow:hidden; vertical-align: middle; }
#divSubMenu { background-color: #90BFE7; line-height: 28px; padding: 10px; vertical-align: middle; }
#sectionBar {
z-index:1000;
position:absolute; right:10px; top:13px; width:200px; bottom:75px; /* footer height + 25px */
border:solid 2px #90bfe7; background-color:#ffffff;
padding:15px 10px;
}
#footerPage { position:relative; padding:10px; background-color:#90bfe7; color:#000; }
#sectionPage { padding:12px 10px 10px 10px; width:700px; }
</style>
</head>
<body>
<div class="wrapper">
<div id="sectionBar">
<div id="divBarContent">
<div>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc blandit aliquam metus non imperdiet. Vivamus eu velit a velit pellentesque faucibus. Donec massa erat, fermentum vel laoreet non, commodo sit amet nulla. In placerat, magna ac fringilla varius, justo ante rutrum magna, vel interdum nisi eros vel nibh. Cras aliquet metus tristique velit vulputate mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu dignissim nisi.
Nulla vitae ante magna, sed pharetra nunc. Donec tincidunt dignissim mi ac tempus. Fusce ut ante tellus, et egestas libero. Donec facilisis, tellus at sagittis iaculis, arcu orci posuere elit, a luctus odio nunc ac sem. Etiam at erat et neque tristique eleifend. Curabitur blandit turpis sit amet tortor tempor eu euismod ligula sollicitudin. Suspendisse non sapien eu nibh faucibus feugiat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;
Integer quam turpis, porttitor nec congue convallis, fringilla sit amet purus. Donec at elit mauris. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec ligula tellus, rhoncus eget faucibus vitae, bibendum vel arcu. Pellentesque ante lectus, sodales at interdum sit amet, sollicitudin cursus quam. Fusce eget orci vel eros scelerisque dictum. Cras facilisis, metus vitae venenatis aliquet, nibh sem blandit mi, sit amet viverra massa ipsum ut quam. Vivamus vitae nunc eget justo pellentesque mollis vel non justo. Mauris tempus mattis rutrum. Donec nec viverra nulla. Cras commodo felis sit amet nulla fringilla mollis.
</div>
</div>
</div>
<div id="headerPage">
<div id="navPage">menu</div>
<div id="divHeaderImg"></div>
<div id="divSubMenu">sub menu</div>
</div>
<div id="sectionPage">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc blandit aliquam metus non imperdiet. Vivamus eu velit a velit pellentesque faucibus. Donec massa erat, fermentum vel laoreet non, commodo sit amet nulla. In placerat, magna ac fringilla varius, justo ante rutrum magna, vel interdum nisi eros vel nibh. Cras aliquet metus tristique velit vulputate mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu dignissim nisi.
Nulla vitae ante magna, sed pharetra nunc. Donec tincidunt dignissim mi ac tempus. Fusce ut ante tellus, et egestas libero. Donec facilisis, tellus at sagittis iaculis, arcu orci posuere elit, a luctus odio nunc ac sem. Etiam at erat et neque tristique eleifend. Curabitur blandit turpis sit amet tortor tempor eu euismod ligula sollicitudin. Suspendisse non sapien eu nibh faucibus feugiat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc blandit aliquam metus non imperdiet. Vivamus eu velit a velit pellentesque faucibus. Donec massa erat, fermentum vel laoreet non, commodo sit amet nulla. In placerat, magna ac fringilla varius, justo ante rutrum magna, vel interdum nisi eros vel nibh. Cras aliquet metus tristique velit vulputate mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu dignissim nisi.
</div>
<div id="divPush"></div>
</div>
<div id="footerPage">footer</div>
</body>
</html>
Leave your HTML as-is, change your CSS to this:
/* Sticky Footer */
{ margin: 0; }
html, body, form { height: 100%; }
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -50px; /* the bottom margin is the negative value of the footer's height */
clear:both;
}
#footerPage, #divPush
{
height: 50px; /* .push must be the same height as .footer */
}
/* End / Sticky Footer */
body { background-color:#000; width:960px; margin:0 auto; position:relative; font-family:Tahoma, Verdana; }
div.wrapper { background-color:#fff; position:relative; }
#headerPage { width:960px;position:absolute;top:0;left:0; }
#divHeaderImg { height:100px; }
#navPage { height:30px; line-height: 30px; font-size:16px; background-color:#90bfe7; padding:0 10px; position:relative; overflow:hidden; vertical-align: middle;width:940px; }
#divSubMenu { background-color: #90BFE7; line-height: 28px; padding: 10px; vertical-align: middle; }
#sectionBar {
z-index:1000;
position:relative; float:right;right:10px; top:13px; width:200px; bottom:75px; /* footer height + 25px */
border:solid 2px #90bfe7; background-color:#ffffff;
padding:15px 10px;
}
#divPush {clear:both;}
#footerPage { position:relative; padding:10px; background-color:#90bfe7; color:#000; }
#sectionPage { padding:12px 10px 10px 10px; width:700px;padding-top:190px; }
P.S. this is a bad question.
I am going to give you the benefit of the doubt and say you're working for an unreasonable client or with some uneditable HTML markup and you need to do some sort of hack to get this presentable.
Otherwise, there's no excuse for taking this approach.
I made some changes on the code you posted, I hope that helps !`
<style type="text/css">
/* Sticky Footer */
{ margin: 0; }
html, body, form { height: 100%; }
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -50px; /* the bottom margin is the negative value of the footer's height */
}
#footerPage
{
height: 50px; /* .push must be the same height as .footer */
}
#divPush {height: 800px; }
/* End / Sticky Footer */
body { background-color:#000; width:960px; margin:0 auto; position:relative; font-family:Tahoma, Verdana; }
div.wrapper { background-color:#fff; position:relative; }
#headerPage { }
#divHeaderImg { height:100px; }
#navPage { height:30px; line-height: 30px; font-size:16px; background-color:#90bfe7; padding:0 10px; position:relative; overflow:hidden; vertical-align: middle; }
#divSubMenu { background-color: #90BFE7; line-height: 28px; padding: 10px; vertical-align: middle; }
#sectionBar {
z-index:1000;
right:10px; top:13px; width:200px; /* footer height + 25px */
border:solid 2px #90bfe7; background-color:#ffffff;
padding:15px 10px;
display:inline;
float:right;
height: 100%;
}
#footerPage { position:relative; padding:10px; background-color:#90bfe7; color:#000; }
#sectionPage { padding:12px 10px 10px 10px; width:700px; }
</style>`
I might be confused on what you are looking for, but why not add overflow:auto under the id=sectionBar? That way if the content if greater than your box it will add a scroll bar and not flow over the footer. Again, maybe I am missing the question or the end result you are looking for.
#lorenzo.macon is right - you need to avoid using position: absolute, and use a float instead.
One of your issues was also that your footer needs to have the same total height as the negative margin of the wrapper; it looks like perhaps you weren't accounting for padding and/or borders in the equation.
The supplied code includes the sidebar second in the code, so that if it were not floated (e.g., for a responsive layout), it would come later. But you can actually have it either way, and it should work.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<style type="text/css">
/* LAYOUT */
/* Original Sticky Footer: http://ryanfait.com/sticky-footer/ */
* { margin: 0 }
html, body, .wrapper {
height: 100%;
}
body {
margin: 0 auto;
position: relative;
}
.wrapper {
position: relative;
min-height: 100%;
height: auto !important;
margin: 0 auto -70px; /* bottom margin = -1 x ( #footerPage height + padding + border ) */
}
#footerPage, #divPush {
height: 50px; /* .push must be the same height as .footer */
padding: 10px; /* must have same padding! */
}
#divPush {
clear: both;
}
/* End / Sticky Footer */
#sectionPage {
width: 70%;
float: left;
}
/*
#sectionBar has percentage for L+R padding, so can calculate w/ #sectionPage
and ems for T+B padding so can relate to typography. This is less important.
*/
#sectionBar {
width: 20%;
padding: 2em 5%;
margin-left: -1px; /* IE7 needed this */
float: right;
display: inline; /* Fix for IE5/6 doubled float margin issues - see http://www.positioniseverything.net/explorer/doubled-margin.html */
}
/* VISUAL STYLE separated for clarity */
body {
background: #000;
max-width: 960px; /* use max-width for flexible layouts */
font-family: Tahoma, Verdana;
}
div.wrapper { background: #fff }
#divHeaderImg { height: 100px; }
#navPage { background: #90bfe7; padding: .5em; }
#divSubMenu {
background: #90bfe7;
padding: .5em;
}
#sectionBar {
background: #fcf;
}
#footerPage {
position: relative;
background: #90bfe7;
}
#content {
background: #ffc;
padding: 12px 10px 10px 10px;
}
</style>
</head>
<body>
<div class="wrapper">
<div id="sectionPage">
<div id="headerPage">
<div id="navPage">menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu menu </div>
<div id="divHeaderImg"></div>
<div id="divSubMenu">sub menu</div>
</div><!-- #headerPage -->
<div id="content">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc blandit aliquam metus non imperdiet. Vivamus eu velit a velit pellentesque faucibus. Donec massa erat, fermentum vel laoreet non, commodo sit amet nulla. In placerat, magna ac fringilla varius, justo ante rutrum magna, vel interdum nisi eros vel nibh. Cras aliquet metus tristique velit vulputate mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu dignissim nisi.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc blandit aliquam metus non imperdiet. Vivamus eu velit a velit pellentesque faucibus. Donec massa erat, fermentum vel laoreet non, commodo sit amet nulla. In placerat, magna ac fringilla varius, justo ante rutrum magna, vel interdum nisi eros vel nibh. Cras aliquet metus tristique velit vulputate mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu dignissim nisi.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc blandit aliquam metus non imperdiet. Vivamus eu velit a velit pellentesque faucibus. Donec massa erat, fermentum vel laoreet non, commodo sit amet nulla. In placerat, magna ac fringilla varius, justo ante rutrum magna, vel interdum nisi eros vel nibh. Cras aliquet metus tristique velit vulputate mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu dignissim nisi.
</div>
</div><!-- #sectionPage -->
<div id="sectionBar">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc blandit aliquam metus non imperdiet. Vivamus eu velit a velit pellentesque faucibus. Donec massa erat, fermentum vel laoreet non, commodo sit amet nulla. In placerat, magna ac fringilla varius, justo ante rutrum magna, vel interdum nisi eros vel nibh. Cras aliquet metus tristique velit vulputate mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu dignissim nisi.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc blandit aliquam metus non imperdiet. Vivamus eu velit a velit pellentesque faucibus. Donec massa erat, fermentum vel laoreet non, commodo sit amet nulla. In placerat, magna ac fringilla varius, justo ante rutrum magna, vel interdum nisi eros vel nibh. Cras aliquet metus tristique velit vulputate mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu dignissim nisi.
</div>
<div id="divPush"></div>
</div><!-- .wrapper -->
<div id="footerPage">footer</div>
</body>
</html>
You can't make the bar absolute with top and bottom "margins" and expect it to grow beyond the size you're telling it to be.
Below is a slightly different approach which looks very much (exactly?) like yours. I didn't test in other browsers than firefox 8 so I can't guarantee that it's bulletproof, but this should at least give you an alternative idea:
<!doctype html>
<head>
<style type="text/css">
/* Sticky Footer */
{ margin: 0; }
html, body, form { height: 100%; }
.wrapper {
min-height: 100%;
height: auto !important;
height: 100%;
margin: 0 auto -50px; /* the bottom margin is the negative value of the footer's height */
}
#footerPage, #divPush
{
height: 50px; /* .push must be the same height as .footer */
}
/* End / Sticky Footer */
body { background-color:#000;
width:960px;
margin:0 auto;
position:relative;
font-family:Tahoma, Verdana;
}
div.wrapper {
background-color:#fff; position:relative;
border:2px solid pink;
}
#headerPage {
border:2px solid green;
}
#divHeaderImg { height:100px; }
#navPage {
height:30px;
line-height: 30px;
font-size:16px;
background-color:#90bfe7;
padding:0 10px;
/*
position:relative;
overflow:hidden;
*/
vertical-align: middle;
border:2px solid lime;
}
#leftBox {
border:2px solid yellow;
float;left;
}
#divSubMenu {
border:2px solid darkgreen;
background-color: #90BFE7;
line-height: 28px;
padding: 10px;
vertical-align: middle;
}
#divBarContent {
border:1px solid firebrick;
}
#divBarContent div {
border:1px solid cyan;
}
#sectionBar {
z-index:1000;
/*
position:absolute; right:10px; top:13px; width:200px; bottom:75px;
*/
border:solid 2px #90bfe7; background-color:#ffffff;
padding:15px 10px;
float:right;
margin:0px 10px 25px 0px;
width:200px;
/*
*/
}
/*
*/
/* footer height + 25px */
#footerPage { position:relative; padding:10px; background-color:#90bfe7; color:#000; }
#sectionPage { padding:12px 10px 10px 10px; width:700px; }
</style>
</head>
<body>
<div class="wrapper">
<div id="sectionBar">
<div id="divBarContent">
<div>
# Update from 2.0-BETA3 to 2.0-BETA4
## XML Driver <change-tracking-policy /> element demoted to attribute
We changed how the XML Driver allows to define the change-tracking-policy. The working case is now:
# Update from 2.0-BETA2 to 2.0-BETA3
## Serialization of Uninitialized Proxies
As of Beta3 you can now serialize uninitialized proxies, an exception will only be thrown when
trying to access methods on the unserialized proxy as long as it has not been re-attached to the
EntityManager using `EntityManager#merge()`. See this example:
The Collection interface in the Common package has been updated with some missing methods
that were present only on the default implementation, ArrayCollection. Custom collection
implementations need to be updated to adhere to the updated interface.
</div>
</div>
</div>
<div id="leftBox">
<div id="headerPage">
<div id="navPage">menu</div>
<div id="divHeaderImg"></div>
<div id="divSubMenu">sub menu</div>
</div>
<div id="sectionPage">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc blandit aliquam metus non imperdiet. Vivamus eu velit a velit pellentesque faucibus. Donec massa erat, fermentum vel laoreet non, commodo sit amet nulla. In placerat, magna ac fringilla varius, justo ante rutrum magna, vel interdum nisi eros vel nibh. Cras aliquet metus tristique velit vulputate mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu dignissim nisi.
Nulla vitae ante magna, sed pharetra nunc. Donec tincidunt dignissim mi ac tempus. Fusce ut ante tellus, et egestas libero. Donec facilisis, tellus at sagittis iaculis, arcu orci posuere elit, a luctus odio nunc ac sem. Etiam at erat et neque tristique eleifend. Curabitur blandit turpis sit amet tortor tempor eu euismod ligula sollicitudin. Suspendisse non sapien eu nibh faucibus feugiat. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc blandit aliquam metus non imperdiet. Vivamus eu velit a velit pellentesque faucibus. Donec massa erat, fermentum vel laoreet non, commodo sit amet nulla. In placerat, magna ac fringilla varius, justo ante rutrum magna, vel interdum nisi eros vel nibh. Cras aliquet metus tristique velit vulputate mollis. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque eu dignissim nisi.
<br> <br> <br> <br> <br> <br> moo
</div>
<div id="divPush"></div>
</div>
<div style="clear:both;">
</div>
<div id="footerPage">footer</div>
</body>
</html>
You can probably use position:relative; instead because absolute will make your elements go behind it unless you use z-index: then the elements will go on top of it. Look at this sticky footer if you really have to build it this way
http://www.cssstickyfooter.com/using-sticky-footer-code.html
Edit:
I'm not sure what you are trying to accomplish really. Because the current way the HTML built isn't really semantic for what you're doing. Since sectionBar is a side bar it shouldn't be above your main content it should be structured after after your sectionPage content. You should also be using floats instead of position. That way you don't have to deal with z-index and content going behind. The page would also expand correctly using float but you would have to make use of a .clearfix hack for IE mainly.
There's also almost never a case where you have to build something a certain way. The only time that's a case is if your using a CMS or per-existing old code. So if your not getting an effect you want then you need to look at your Semantic structure of your code.
I saw in one of your comments that this is based on a photoshop layout which leads me to believe you are building this from scratch and means you have complete control over the HTML. So if that's the case then saying it has to be built this way is unacceptable.
It is solvable. You can do it by floating #sectionBar as #lorenzo.marcon mentioned.
You'd need to move #sectionBar to right before#sectionPage` and wrap both elements. I've also added a clearfix to the wrapper.
See this fiddle for the solution.
I'd remove position:absolute; and add a float:right; in #sectionBar definition.
Then add a <br clear="all" /> immediately before closing the div with class "wrapper".
Then you will have to reposition your elements. Work on margins and paddings to get the desired result.
The problem you describe is caused by position:absolute behaviour. In fact, with absolute positioning, the element is removed from the natural flow of the html, and as the name suggests, absolutely positioned :) Thus, the other elements (e.g. footer) go "under" it.

Resources