Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy positioning types

    Hey everyone,

    I'm just looking for some clear cut definitions for positioning types: absolute, relative, static, inherit. One of the main reasons I want to figure this out is because I find it very convenient to use z-indexing w/ some layouts, however it's come to my attention that positioning needs to be declared for an elements z-indexing to work.

    So I guess my question is two fold: 1, what are the definitions for the different types of positioning, i'm astonished that w3schools' site doesn't have any definitive reference to this. My second question would then be what is required for z-indexing to take place.

    Thank you in advance,
    reza ryan naghibi

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,700
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    position: relative; positions the element relative to its usual position. E.g. use bottom: 10px; to move it 10px towards the top.
    position: absolute; positions the element relative to its parent element if that one is positioned relative. If it's not it will position it relative to the <html> element (=the browser window). Rather complicated to explain.
    That means if a div is positioned relative and top: 20px; the absolutely positioned div inside the first one will use the top left corner of the parent as starting point for any positioning, hence it will start from 20px.
    If you apply left: 30px; to the inner div it will be moved 30px to the left and stand at 20px from top that the outer div was already moved. Same goes for the bottom. If the outer div is 20px high and the inner div has bottom: 0; it will stick to the bottom of the outer element and move down if you increase the size of the outer div.
    position: static; is the default value. You only need that if you wanna revert any other positioning from an element if you specified differently before.
    And you use position: inherit; if you want to inherit a specific kind of positioning from a rule directly before that one in the CSS.

    z-index only works on relative and absolute positionings. The higher the value the more the element is "on top".


    I hope I could explain it clearly enough.
    Last edited by VIPStephan; 05-02-2006 at 10:17 PM.

  • #3
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,302
    Thanks
    28
    Thanked 276 Times in 270 Posts
    absolute positioning is absolute; it overrides the objects positioning with regards to everything else on the page and allows you to set the object's distance relative to the browser window with the top, right, bottom, and left CSS properties. It essentially becomes independent of its surroundings. Note that the element will be in its default position from the start though until you actually set the four mentioned positioning properties .

    relative positioning sets the object's position relative to its default location on the page. The top, right, bottom, and left properties alter the object's position relative to this original location.

    inherit, the default positioning, makes elements inherit the positioning of their parent element. So if you have an image in an absolutely positioned box, that image would inherit the absolute positioning and move with it.

    static is the seemingly true default positioning since if no positioning is set, all elements inherit a position of static. The positioning properties don't have any effect on a static element.

    fixed prevents an element from moving even if you scroll, for example.

    Here's an explanation I found on positioning: http://www.quirksmode.org/css/position.html

    All elements have a default z-index value of zero. Elements with a higher index will overlap those with a lower index. The exception seems to be negative z-indices since Mozilla (e.g., Firefox) handles them in a peculiar way; see this explanation for details on that.

    edit: *shakes fist at VIPStephan*
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,700
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    I typed like devil was behind me.
    But I like your explanation - sounds more sorted. And I forgot about fixed.

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    The Netherlands, Baarn, Ut.
    Posts
    4,252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Flow

    Looks like you guys have just about everything covered; I just like to add that with relative positioning, the area on the page that would have been occupied by the positioned element is maintained and the rest of the content flows accordingly, while an absolutely positioned element is taken out of the normal flow completely: the remaining content flows as if it never were there.

    And:
    position: absolute; positions the element relative to its parent element if that one is positioned relative.
    Relative or absolute, actually, but relative is very popular to turn an element into a positioning parent because it can be applied without further consequence for the reason mentioned above.

    If anyone is interested in the finer details of the visual formatting model: they can be found here (especially the bit about stack levels and z-indexing is... compelling... *yawn*).
    Regards,
    Ronald.
    ronaldvanderwijden.com

  • #6
    New Coder
    Join Date
    Mar 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i wna basically learn whether or not i am going to sacrifice document flow if i were to z-index a few elements, (i say a few because you'd have to have 2 elements z-indexed in order for them to display as one would desire.)

    let's say i have 3 boxes. 1 box will be the viewport, the other 2 will be rectangles, one horizontally opposed, one vertically opposed. I want the Viewport box to contain txt and be the lower-most element. I want the width-long rectangle to be the header at the top, and i want the height-long rectangle to be slightly overlapping the header box at the top, but i want the txt w/in the viewport to be pushed accordingly w/ let's say a 1em margin clearing the txt from the other 2 boxes.

    The reason this is very important to me is because my job for the next 2 months is to create next to 2000 design templates for a single html file; thus i need to figure out a lot of css quirks and all that jazz.

    so by token of what i've learned via these posts, i can basically issue a value of "relative" or "auto" to a z-indexed element and hope that it doesnt hurt document flow?

    why can't there be some sort of grouping selector for css that lets you combine several divs and say that you want 1em margin. lol...
    reza ryan naghibi

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    The Netherlands, Baarn, Ut.
    Posts
    4,252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Grouping selector

    The good folks at the W3C are working on that for CSS 3...
    Regards,
    Ronald.
    ronaldvanderwijden.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •