I think this is because I'm floating all three divs "columns" to the left, inside of the main body div.
How can I tell the main body div to expand as big as it needs to fit the content divs?
Here it's with min-height:
And here with the min-height taken away:
Here is my relevant code.
#body
{
border:1px solid blue;
width:950px;
margin-left:auto;
margin-right:auto;
margin-top:15px;
}
#leftcolumn
{
min-height:500px;
float:left;
width:190px;
}
#contactarea
{
font-family:Arial;
}
#contactarea p.heading
{
Color:#000;
font-size:large;
position:relative;
left:14px;
}
#contactarea p.tag
{
color:#000;
font-size:medium;
position:relative;
left:10px;
}
#leftnavigation ul
{
margin:0;
padding: 0;
list-style: none;
}
#leftnavigation ul li {
border-top: 1px solid #333;
border-bottom: 1px solid #111;
}
#leftnavigation ul li:first-child {border-top: none;}
#leftnavigation ul li:last-child {border-bottom: none;}
#leftnavigation ul li a
{
padding: 10px;
display: block;
color: #fff;
background-color:#222222;
text-decoration: none;
}
#leftnavigation ul li a:hover {background: #111;}
#contentarea
{
border:1px solid blue;
min-height:500px;
float:left;
width:594px;
margin-left:5px;
margin-right:5px;
}
#advertisingarea
{
width:150px;
float:left;
min-height:500px;
background-image:url('images/advertisingAreaBackground.png');
background-repeat:repeat-y;
}
.advert
{
height:190px;
overflow:hidden;
}
.advert img
{
padding:0;
margin:0;
position:relative;
left:25px;
top:5px;
}
.advert p
{
font-size:x-small;
font-family:Arial;
margin-left:8px;
margin-right:8px;
margin-top:5px;
}
<div id="body">
<div id="leftcolumn">
<div id="leftnavigation">
<ul>
<li>Automoviles</li>
<li>Clases y Talleres</li>
<li>Electronicos</li>
<li>Inmobiliaria</li>
<li>Libros</li>
<li>Musica, Peliculas y Juegos</li>
<li>Ninos</li>
<li>Otros</li>
<li>Ropa</li>
</ul>
</div>
<div id="contactarea">
<p class="heading">Anuncios Premium</p>
<p class="tag">Destaque sus anuncios con una cuenta premium!</p>
</div>
</div>
<div id="contentarea">sdfg<h1>asdasd</h1></div>
<div id="advertisingarea">
<div class="advert">
<img src="../../Content/images/advertImage.png" alt="Advert" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nibh nisi, volutpat a vehicula eget</p>
</div>
<div class="advert">
<img src="../../Content/images/advertImage.png" alt="Advert" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nibh nisi, volutpat a vehicula eget</p>
</div>
<div class="advert">
<img src="../../Content/images/advertImage.png" alt="Advert" />
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris nibh nisi, volutpat a vehicula eget</p>
</div>
</div>
</div>
The easiest way is just to set the oveflow of the container:
#body
{
...
overflow: auto;
}
For a div to "wrap" around the elements it contains you have to float it (float:left) if you have already floated other elements.
For the floated div to be centered the best cross-browser solution is to wrap it on another not-floated div (invisible) and center that div. Something like this:
<div id="centered">
<div id="floated">
</div>
</div>
This way you can have the inside div wrapping the elements it contains while not specifying any hieght value, while the outer div (invisible, just with width) keeps it centered ;)
you should use firebug to resolve css issues like this. You'd be surprised how useful it is.
In answer to your question -
It has no height because of the floating elements. You need to clear the floats within that element for the parent to display as expected. You can do this a few ways.
make a clear class and simply add it as an element after the floats:
<style>
.clear{clear:both;}
</style>
<div class="parent">
<div class="float_left">left</div>
<div class="float_right">right</div>
<div class="clear"></div>
</div>
a more proper auto clear for any element that has a class of "container":
<style>
.container:after {
content: ".";
display: block;
clear: both;
visibility: hidden;
line-height: 0;
height: 0;
}
.container {
display: inline-block;
}
html[xmlns] .container {
display: block;
}
* html .container {
height: 1%;
}
</style>
<div class="parent container">
<div class="float_left">left</div>
<div class="float_right">right</div>
</div>
Related
Beginner doubt: I would like to hide the parent div when the child div is visible. Is this possible to do with css? maybe using the z-index?
Another thing, Can I format the child div with different css atributes, or they need to be the same ones of the parent?
Thanks!
<!doctype html>
<style type="text/css">
#intro {
width:100%;
float:left;
padding-top:3%;
background-repeat:no-repeat;
background-size:100%;
position:relative;
z-index:50;
}
.wrapper_intro {
display:block;
width:38%;
margin: 7% 3% 3% 7%;
float:right;
color:black;
padding:3% 3% 4% 3%;
background-color:none;
position:absolute;
z-index:100;
right: 0px;
}
.parent {
display:block;
font-size:5em;
color:yellow;
margin-top: 2%;
margin-bottom:3%;
text-align:center;
z-index: 102;
}
.child {
display:none;
}
.parent:hover .child {
display:block;
background-color: rgba(242, 218, 192, 0.9);
margin-top:5%;
color:black;
text-align:center;
z-index: 101;
}
</style>
<div class="wrapper_intro">
<div class="parent">
<div>Ola!</div>
<div class="child">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</div>
</div>
When you hide a parent div, all elements inside it also will get hidden.
Didn't understand ur scenario. If you want them to be separate, don't nest them in a div. Keep them separate.
Yes the css can be different for parent and child. You can use !important to over ride any css already used for parent.
Due to comment it should be quite simply, what about adding just
.parent:hover > div:first-child {visibility: hidden}
http://jsfiddle.net/czd1z5jh/
OR if you want to move .child to the top:
.parent:hover > div:first-child {display: none}
http://jsfiddle.net/czd1z5jh/1/
I have problem with position: absolute and floats...
As you can see in fiddle, when you resize browser, text from left side goes below the image, but what I want is to go above the image.
When I remove position: absolute on .image-ipad, it works like that, but in my project I need image to stick on left side, and text on right side (normal)
Code:
HTML
<section class="case eat-login">
<div class="row">
<h3 class="stick-right">Login Screen</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<img class="image-ipad" src="http://www2.pcmag.com/media/images/362825-apple-ipad-mini.jpg?thumb=y" width="300px">
<div style="clear:both;"></div>
</div>
</section>
CSS
.stick-right{
float:right;
clear:both;
}
.eat-login {
position: relative;
padding: 130px 0 130px;
clear: both;
}
.eat-login p{
text-align: right;
float: right;
clear: both;
width: 45%;
font-size: 15px;
font-family: "Proxima Nova";
color:#9e9d9d;
line-height: 25px;
}
img.image-ipad {
left:0px;
top:40px;
}
JSFiddle: http://jsfiddle.net/jt9jk2g0/6/
Thanks!
You could do it by using css #media queries for small screen size:
JSFiddle - DEMO
HTML:
<section class="case eat-login">
<div class="row">
<img class="image-ipad" src="http://www2.pcmag.com/media/images/362825-apple-ipad-mini.jpg?thumb=y" width="300px">
<h3 class="stick-right">Login Screen</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</p>
<div style="clear:both;"></div>
</div>
</section>
CSS:
.stick-right {
float:right;
clear:both;
}
.eat-login {
position: relative;
padding: 130px 0 130px;
clear: both;
}
img {
position: absolute;
}
.eat-login p {
text-align: right;
float: right;
clear: both;
width: 45%;
font-size: 15px;
font-family:"Proxima Nova";
color:#9e9d9d;
line-height: 25px;
}
#media (max-width: 500px) {
h3 {
margin-top:300px;
}
}
the code is the following:
(CSS)
#container {
border:1px dashed #000;
overflow:hidden;
}
#content, #sidebar {
float:left;
width:50%;
}
#content {
background:yellow;
}
#sidebar {
background:grey;
}
#sidebar {
height:100%;
}
(HTML)
<div id="container">
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
</div>
<div id="sidebar">
<p>Few words</p>
</div>
</div>
I would like to see a #sidebar div with same height, like the #content div, is it possible without absolute position? Online version: http://jsfiddle.net/yJbUW/
You can do that by displaying the #container as table and displaying #content and #sidebar as table-cells:
#container {
border:1px dashed #000;
display: table;
width: 100%;
}
#content, #sidebar {
display: table-cell;
width:50%;
}
Check your updated Fiddle.
You can also try below code
CSS goes here
#container {
border:1px dashed #000;
overflow:hidden;
}
#content, #sidebar {
float:left;
width:50%;
}
#content {
background:yellow;
}
#sidebar {
background:grey;
}
#Container
{
height: auto;
width: auto;
}
and update HTML as follows,
<div id="Container">
<span id="content">
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, Lorem ipsum dolor sit amet, consectetuer adipiscing elit</p>
</span>
<span id="sidebar">
<p>Few words</p>
</span>
</div>
It can be solved with
#content, #sidebar {
display: table-cell;
width:50%;
}
.table {
display:table;
}
.row {
display:table-row;
}
.one {
width:200px;
border:1px solid #333;
display:table-cell
}
<div class="table">
<div class="row">
<div class="one">gfhgfhgfhgf</div>
<div class="one">gfhgfhgfhgf</div>
</div>
</div>
Just use this code before the container closing Div, works for me!
<p style="clear:both;"></p>
Here's the simplest and most elegant solution:
#container {
display:grid;
grid-auto-flow: column;
}
Good Day Im new to CSS
And recently after I have finish my first project, an extra white space came up on my page, Then I have found out that the hr tag that I am using is one reason why there an extra white space(I guess?) , when I put hr size
#hr{
width:960px;
margin: 0px auto;
color:#C0C0C0;
height: 12px;
margin-bottom:15px;
overflow:hidden;
}
white page will appear
But when I put
#hr {
width:70%;
margin: 0px auto;
color:#C0C0C0;
height: 12px;
margin-bottom:15px;
overflow:hidden;
}
This will be ok but zooming it in/out will move the hr line,
If needed I'll post the codes but my codes is so many...
Right, I think ill put my codes,
HTML CODES:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Beginner</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
<style type="text/css">
</style>
</head>
<body>
<div id="top-most">
</div>
<div id="wrapper">
<div id="logo">
<img alt="logo" src="images/logo.png" />
</div>
<div id="header">
<p>info#CreativeStudio.com</p>
</div>
<div id="top-bar-selection" >
<ul>
<li>HOME</li>
<li> ABOUT US </li>
<li> PORTFOLIO </li>
<li> SERVICES </li>
<li> BLOG </li>
<li> CONTACT US </li>
</ul>
</div>
</div>
<hr id="hr" />
<div id="banner">
<object id="flash1" data="Beginner.swf" type="application/x-shockwave-flash" style="width: 960px; height: 380px">
<param name="movie" value="Beginner.swf" />
</object>
</div>
<div id="hr2">
<hr />
</div>
<div id="information">
<div id="about-us-section">
<div id="about-us">
<h3>→ ABOUT US</h3>
</div>
<div id="hr">
<hr />
</div>
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis nulla id orci malesuada porta posuere quis massa. Nunc vitae purus non augue scelerisque ulitricies vitae et velit. Sed vitae lectus id sem lobortis scelerisque. Praesent eget consequat libero.</p>
<p style="height: 3px"></p>→<h4>Read</h4>
</div>
</div>
<div id="our-benefits-section">
<div id="our-benefits">
<h3>→ OUR BENEFITS</h3>
</div>
<div id="hr">
<hr />
</div>
<div id="content">
<p>☑Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis nulla id orci malesuada porta posuere quis massa. </p>
<p>☑ Nunc vitae purus non augue scelerisque ulitricies vitae et velit. Sed vitae lectus id sem lobortis scelerisque. Praesent eget consequat</p>
<p>☑Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis nulla id orci malesuada porta posuere quis massa. </p>
</div>
</div>
<div id="testimonials-section">
<div id="testimonials">
<h3>→ TESTIMONIALS</h3>
</div>
<div id="hr">
<hr />
</div>
<div id="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis nulla id orci malesuada porta posuere quis massa. Nunc vitae purus non augue scelerisque ulitricies vitae et velit. Sed vitae lectus id sem lobortis scelerisque. Praesent eget consequat libero.</p>
<h5>Rafi, Graphicsfuel.com</h5></div>
</div>
</div>
<div id="hr">
<hr />
</div>
<div id="our-portfolio-section">
<div id="our-portfolio">
<h3>→ OUR PORTFOLIO</h3>
</div>
<img alt="PortfolioA" src="images/Portfolio A.jpg" id ="picA" />
<img alt="PortfolioB" src="images/Portfolio B.jpg" id ="picB"/>
<img alt="PortfolioC" src="images/Portfolio C.jpg" id ="picC"/>
<img alt="PortfolioD" src="images/Portfolio D.jpg" id ="picD"/>
</div>
<div id="hr">
<hr />
</div>
<div id="information2">
<div id="blog-updates-section">
<div id="blog-updates">
<h4>→ BLOG UPDATES</h4>
</div>
<div class="content">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque quis nulla id orci malesuada porta posuere quis massa. Nunc vitae purus non augue scelerisque ulitricies vitae et velit. Sed vitae lectus id sem lobortis scelerisque. Praesent eget consequat libero.</p>
</div>
</div>
<div id="socialmedia">
<h6> → CONNECT WITH US</h6>
<img alt="" src="images/Icon/Twitter.png" />
<img alt="" src="images/Icon/Facebook.png" />
<img alt="" src="images/Icon/Flickr.png" />
<img alt="" src="images/Icon/RSS.png" />
</div>
</div>
<div id="footerbgcolor">
<div id="footer">
<div class="below-bar-selection">
<p>Home | About Us | Portfolio | Services | Blog | Contact Us</p>
<p>© 2010 CreativeStudio. All Rights Reserved</p>
</div>
<div class="logo-small" style="left: 770px; top: 1240px; width: 128px">
<img alt="" src="images/Icon/Logo%20Small.png" />
</div>
</div>
</div>
</body>
</html>
CSS CODES:
#top-most { background-color:black; height:17px; }
#wrapper { width :960px; height:130px ; margin:0px auto; background-color: #F4F4F4; overflow:hidden; }
#logo { margin: 19px 0 0 10px; float:left; }
#header { float: right; margin: 19px 3px 0 0; }
#header p { color: #979899; }
#top-bar-selection { width:960px;position :absolute ; overflow:hidden; display:inline-block; margin:70px auto 0 -160px; word-spacing:1px; letter-spacing:1px;}
#top-bar-selection ul{color:orange; text-align: right; }
#top-bar-selection ul li {display :inline; font-size:12px; font-family: arial black; margin: 0 32px 0 0;}
#top-bar-selection ul li a:link {color: #fe9a00; font-family: Arial black; }
#top-bar-selection ul li a:hover {color: #000000; font-family: Arial black; }
#hr { width: auto; margin: 0px auto; color:#C0C0C0; height: 12px; margin-bottom:15px; overflow:hidden;}
#hr2 { width:960px; margin: 0px auto ; margin-top:10px; height:9px;}
#banner { width:960px; height:380px ; margin:0px auto; background-color: black; }
#information { width:960px; margin :0px auto 0 auto; height:235px; padding-top : 15px; margin-top:13px; }
#about-us-section { width: 266px; margin-right: 600px; background-color: #F4F4F4; position:absolute; padding-right: 10px; }
#about-us-section hr { background-color:black; height:7px; width:260px; margin:10px 0 0 0; position:absolute; }
#about-us-section p { padding-top: 10px; font-weight:lighter;}
#about-us-section h4 { color:#FF9933; display:inline; line-height:30px;}
#about-us-section h4 a:link {color: #fe9a00; font-family: Arial black; }
#about-us-section h4 a:active {color: #fe9a00; font-family: Arial black;}
#about-us-section h4 a:visited {color: #fe9a00; font-family: Arial black;}
#about-us-section h4 a:hover { color:#000000; }
#our-benefits-section { width: 270px; margin: 0 0 0 355px; background-color : #F4F4F4; position:absolute; padding-right: 10px;}
#our-benefits-section hr { background-color:black; height:7px; width:260px; margin:10px 0 0 0; position:absolute; }
#our-benefits-section p { padding-top: 10px; }
#testimonials-section { width: 270px; margin: 0 0 0 700px; position:absolute; padding-right: 10px; }
#testimonials-section hr { background-color:black; height:7px; width:260px; margin:10px 0 0 0; position:absolute; }
#testimonials-section p { padding-top: 10px; font-weight:300; }
#testimonials-section h5 { padding-top: 10px; font-style:italic; }
#our-portfolio-section { width:960px; margin: 0px auto 0 auto; display: block; height:205px; }
#our-portfolio-section our-portfolio { margin: 5px 2px 0 0; }
#our-portfolio-section img { padding: 15px; display:inline;}
#information2 { width:960px; margin :0px auto 0 auto; height:145px; margin-top:5px; }
#blog-updates-section { width:600px; height:50px; position:absolute; }
#blog-updates-section h3 {margin: 8px 5px 0 0; line-height:10px;}
#blog-updates-section p {margin: 28px 5px 0 0; }
#blog-updates .content { margin: 28px 5px 0 0; float:left; position:absolute;}
#socialmedia { float:right; overflow:hidden; position:absolute;margin: 10px 720px; width: 150px; height: 125px; width:200px;}
#socialmedia h6 { font-size:10px;}
#socialmedia img { padding: 6px; margin-top:20px; }
#footerbgcolor { background-color:#E2E2E2; height:100px; }
#footer { width :960px; height:100px ; overflow:hidden; margin:0px auto; }
#footer .below-bar-selection { margin: 30px 0 0 20px; float:left; width: 750px; }
#footer a:link {color: #000000; font-family: Arial black; }
#footer a:active {color: #000000; font-family: Arial black;}
#footer a:visited {color: #000000; font-family: Arial black;}
#footer h4 a:hover { color:#000000; font-family:Arial black;}
#footer .logo-small { float:right; padding-top: 15px;}
If you already got a better solution, then forget this message,
But i noticed something.
according to your code
#hr {
width: auto;
margin: 0px auto;
color:#C0C0C0;
height: 12px;
margin-bottom:15px;
overflow:hidden;}
Since your id of Wrapper is 960 pixels,
use that width template to set your HR' width value.
so change:
width: auto;
to
width: 958px;
Notice: 960px looks a bit too long, so i shaved some pixels out to fit the alignment. But if 960 looks better, then choose 960.
Well first of all i don't see any white space on right side of the page rather space between the hr tag due to the height you have given.
Secondly,
hr tag will automatically create a line. If you want to give it an id that means you want to add additional styling to the hr element.
If i am understanding properly, than you shouldn't even use WIDTH.
#hr{
// no need to use width as it will automatcally fill it self
margin: 0px auto;
color:#C0C0C0;
height: 12px; // only needed if you want to create space inbetween
margin-bottom:15px;
overflow:hidden;
}
and use it as
<hr id="hr" />
Hope this answers your question.
Since you only posted the CSS code without the HTML code, it may be hard for people to see the whole problem, but from the information you posted, this will be my proposed solution,
This css code:
width:960px;
makes your HR a fixed width of 960 pixels.
This css code:
width:70%;
makes your HR take up 70% of its container's width.
You could just try setting the width to 100%.
p.s. Why do you need it to be 70% ?
hr { //remove # so it will apply to <hr> tag
width:70%;
margin: 10px auto; // change the margin size so the hr line can be seen
color:#C0C0C0;
margin-bottom:15px;
overflow:hidden;
}
I think the problem that could remove the hr line is only about margin. If the margin is set to 0, then the hr line could be override by another tag
i got a tricky situation here. im trying to center 3 divs inside my footer and they need to have dynamic width, like min-width.
[cotainer [first] [second] [third] /container]
my setup is this
<footer>
<div id="container">
<div id="first"></div>
<div id="second"></div>
<div id="third"></div>
</div>
</footer>
footer #container { width: 800px; margin: 0 auto; }
#container #first,#container #second,#container #third
{
float: left;
min-width: 200px;
height: 25px;
background: /* image url */
padding: 4px;
margin: 0 20px 0 0;
}
#container #third { margin-right: 0; }
You should use display: table; and table-cell.
#container {
display:table;
}
#first, #second, #third {
display: table-cell;
width: 200px;
height: 40px;
border: 1px dashed #000;
}
Demo available here.
set container to display as:table and set it's margin to 0 auto.
#container {
display:table;
margn:0 auto;
whitespace: nowrap;
}
#first, #second, #third {
min-width: 200px;
float:left
...
}
Demo: http://jsfiddle.net/AZ4yT/1/
Edit: It gets left aligned in IE. so you might wanna use a workaround for that
What about using display: inline-block? You can see a jsFiddle of it here:
http://jsfiddle.net/S7bKT/1/
HTML
<div id="container">
<div id="first">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Aliquam scelerisque euismod auctor. Sed pulvinar nulla eu
lorem iaculis ultrices. Mauris
</div>
<div id="second">Lorem ipsum dolor sit amet</div>
<div id="third">Sed pulvinar nulla eu lorem iaculis ultrices</div>
</div>
CSS
#container {
width: 500px;
background: #dedede;
margin: 0 auto;
text-align: center;
}
#first, #second, #third {
display: inline-block;
min-width: 50px;
max-width: 120px;
min-height: 100px;
zoom: 1; /* Fix for IE */
_display: inline; /* Hack for IE */
margin-right: 20px;
vertical-align: top;
}
#first {
background: #f00;
}
#second {
background: #0f0;
}
#third {
background: #00f;
}
#container div:last-child {
margin-right: 0;
}