Forum Moderators: not2easy

Message Too Old, No Replies

Very basic layout question

         

davetheman2006

12:26 am on Aug 18, 2009 (gmt 0)

10+ Year Member



I was having trouble with absolute positioning, so I made this very simple CSS code to test my technique. #letterb is running into #letterc, even though I specify for them to occupy their own space. Can someone tell me where I'm going wrong?

code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>letter a test</title>
<style type="text/css">
#total {width:1000px; position:relative;}
#lettera {width:400px; position:absolute; right:600px; left:00px;}
#letterb {width:400px; position:absolute; right:200px; left:400px;}
#letterc {width:200px; position:absolute; right:00px; left:600px;}
</style>

</head>
<body>
<div id="total">
<div id="lettera">
<p>sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text </p>
</div>
<div id="letterb">
<p>sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text </p>
</div>

<div id="letterc">
<p>sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text sample text </p>
</div>
</div>
</body>
</html>

jbinbpt

12:32 am on Aug 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



#letterc {width:200px; position:absolute; right:00px; left:800px;}

swa66

12:32 am on Aug 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're setting too much: the width and the left and right side (and a margin of 0 default at least unless set somewhere?)
esp. where it involves #letterc where it doesn't add up ...

I think you meant to use left:800px on #letterc

dukelips

5:04 pm on Aug 18, 2009 (gmt 0)

10+ Year Member



I have small doubt swa, Y should the container div positioned as relative

swa66

5:13 pm on Aug 18, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



@dukelips:
Position:relative gives an element "position", it means that children of it that have position:absolute use that parent as reference.

If no such parent is found, it will use the viewport as a reference.

dukelips

1:03 am on Aug 19, 2009 (gmt 0)

10+ Year Member



Swa, if the container position is set to absolute what will be the result

swa66

8:35 am on Aug 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



both relative and absolute give the element "position" (to be used as reference for child elements as a reference when absolutely positioned)

but absolute also takes the element itself out of the flow.

SuzyUK

9:29 am on Aug 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thought this might be useful
What position does to the containment of other elements : 10.1 Definition of "containing block" [w3.org]

position:relative;
on an element defines it as the containing block for any further child elements which have position absolute.

@dukelips if you try to absolutely position the overall container you may run into scroll issues/hidden content as you will in effect have removed the entire layout from the flow of the document, there's no reason not to use position relative in this case, though position absolute on the wrapper will intially produce the same effect.


position: absolute;
is like taking a sticky [post-it] note and sticking it on the screen, your scroll bar won't know it's there ;) whereas
position: relative;
keeps the other elements contained and in the flow.

dukelips

2:02 pm on Aug 19, 2009 (gmt 0)

10+ Year Member



is it possible to code a small example for this position model that gets affected if we use absolute positioning