Forum Moderators: not2easy

Message Too Old, No Replies

Help with floats?

         

blindcat

7:24 pm on Mar 28, 2009 (gmt 0)

10+ Year Member



Hello there,

I'm trying to create a liquid header using a 1px wide image and a left and right float for the corner images. The problem is i'm using transparent png's and need to position them on the ends of the div container instead of overlapping. (to give them the same transparency)

Any insight?

<style type="text/css">
body {
font: 80% verdana, arial, helvetica, sans-serif;
text-align: center; /* for IE */
background-color: #333333;
background-image: url(Images/circuit-gradient-380x1050.jpg);
}
#container {
text-align: left; /* counter the body center */
width: 80%;
background-image: url(Images/xrepeatheader.png);
background-repeat: repeat-x;
height: 108px;
margin-right: auto;
margin-left: auto;
}
#container #leftcorner {
background-image: url(Images/leftcornerheader.png);
float: left;
height: 108px;
width: 27px;
}
#container #rightcorner {
background-image: url(Images/rightcornerheader.png);
float: right;
height: 108px;
width: 27px;
}
</style>
</head>
<body>
<div id="container">
<div id="leftcorner"></div>
<div id="rightcorner"></div>
</div>

</body>
</html>

Thanks for your help!

swa66

9:36 pm on Mar 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd try to get IE out of quirks mode first (validate the document, get a full doctype, with nothing in front of it. That way you'll have less fighting to do with IE6.

To get something outside the container div, why not use absolute positioning ?
To stop overloapping, why not set a fixed margin instead of the 80% width (whih leads to unknown sizes of margins


body {
font: 80% verdana, arial, helvetica, sans-serif;
background-color: #333333;
background-image: url(Images/circuit-gradient-380x1050.jpg);
}
#container {
background-image: url(Images/xrepeatheader.png);
background-repeat: repeat-x;
height: 108px;
margin: 0 27px;
}
#container #leftcorner {
background-image: url(Images/leftcornerheader.png);
position: absolute;
top: 0;
left: 0;
height: 108px;
width: 27px;
}
#container #rightcorner {
background-image: url(Images/rightcornerheader.png);
position: absolute;
top: 0;
right: 0;
height: 108px;
width: 27px;
}

Or alternatively do use the 80% width and push the two divs outside it by giving the parent position and using negative margins:


body {
font: 80% verdana, arial, helvetica, sans-serif;
background-color: #333333;
background-image: url(Images/circuit-gradient-380x1050.jpg);
}
#container {
background-image: url(Images/xrepeatheader.png);
background-repeat: repeat-x;
height: 108px;
width: 80%
margin: 0 auto;
position: relative: /* to give the container position */
}
#container #leftcorner {
background-image: url(Images/leftcornerheader.png);
position: absolute;
top: 0;
left: 0;
margin-left: -27px; /* equal to width */
height: 108px;
width: 27px;
}
#container #rightcorner {
background-image: url(Images/rightcornerheader.png);
position: absolute;
top: 0;
right: 0;
margin-right: -27px; /* equal to width */
height: 108px;
width: 27px;
}

blindcat

12:51 am on Mar 30, 2009 (gmt 0)

10+ Year Member



Hi thanks for the great reply, I have already got a doctype as i'm (trying to) use dreamweaver. I think you cracked it although on the right hand side corner I used a relative positioning because it wasn't in sync with the header...

Does this look alright to you?

<!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>Untitled Document</title>
<style type="text/css">
body {
font: 80% verdana, arial, helvetica, sans-serif;
text-align: center; /* for IE */
background-color: #333333;
background-image: url(Images/circuit-gradient-380x1050.jpg);
}
#container {
text-align: left; /* counter the body center */
width: 80%;
background-image: url(Images/xrepeatheader.png);
background-repeat: repeat-x;
height: 108px;
margin-right: auto;
margin-left: auto;
position: relative;
}
#container #leftcorner {
background-image: url(Images/leftcornerheader.png);
float: left;
height: 108px;
width: 27px;
margin-left: -27px;
position: absolute;
}
#container #rightcorner {
background-image: url(Images/rightcornerheader.png);
float: right;
height: 108px;
width: 27px;
margin-right: -27px;
position: relative;
left: 0px;
top: 0px;
}
</style>

blindcat

12:54 am on Mar 30, 2009 (gmt 0)

10+ Year Member



It does look a bit dodgey in dreamweaver though, the right hand side is 27px away from where it's ment to be, but it matches up fine in firefox.