Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
  1. #1
    Member Reza O's Avatar
    Join Date
    Nov 2012
    Posts
    53
    Member #
    33634
    Liked
    1 times
    I have googled and read many articles on this. They all say that relative positioning moves the item relative to where it would have been. But you could move an item with absolute positioning too. You just give it coordinates. So what does relative exactly do that absolute doesn't and when and how is it used?

    Also why doesn't it work if I take position:relative out of the code?

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    div
    {
    width:100px;
    height:100px;
    background:red;
    position:relative;
    animation:mymove 5s infinite;
    -moz-animation:mymove 5s infinite; /* Firefox */
    -webkit-animation:mymove 5s infinite; /* Safari and Chrome */
    -o-animation:mymove 5s infinite; /* Opera */
    }

    @keyframes mymove
    {
    from {top:0px;}
    to {top:200px;}
    }

    @-moz-keyframes mymove /* Firefox */
    {
    from {top:0px;}
    to {top:200px;}
    }

    @-webkit-keyframes mymove /* Safari and Chrome */
    {
    from {top:0px;}
    to {top:200px;}
    }

    @-o-keyframes mymove /* Opera */
    {
    from {top:0px;}
    to {top:200px;}
    }
    </style>
    </head>
    <body>

    <p><b>Note:</b> This example does not work in Internet Explorer.</p>

    <div></div>

    </body>
    </html>

  2.  

  3. #2
    Member
    Join Date
    Nov 2012
    Location
    Tampa. FL
    Posts
    59
    Member #
    33844
    Liked
    21 times
    Relative positioning on it's own doesn't appear to do much at all because it leaves the element where it would be anyway. However, if you specify position:relative and top: 10px, you can move the element down 10px in relation to where it normally would be.

    The biggest difference between relative and absolute is the space taken up. Because position relative leaves the element in the flow of the document, it still takes up the same space. Absolute posititioning takes the element out of the flow of the document so it does not take up the same amount of space (it's basically on a different layer).

    Also, position absolute is positioned in relation to the browser window unless the absolute positioned element is inside an element that is positioned relative.
    twinky likes this.
    Freelance Web Developer

  4. #3
    Junior Member yianna talantios's Avatar
    Join Date
    Dec 2012
    Posts
    14
    Member #
    34278
    Quote Originally Posted by Reza O, post: 245692
    I have googled and read many articles on this. They all say that relative positioning moves the item relative to where it would have been. But you could move an item with absolute positioning too. You just give it coordinates.
    :wavespin:

    Elements have a position value of static by default.

    Code:
    position: static / relative / absolute / fixed;
    * Using a value other then static causes an object to become a positioned element.

    This explains why you can move an element around when you use anything but static. Then you can use top, right, bottom, left values for placement.

    So what does relative exactly do that absolute doesn't and when and how is it used?

    Also why doesn't it work if I take position:relative out of the code?
    relative vs absolute

    relative is just like static except you can use the values mentioned above for placement. Taking out the position property from that code you showed isn't going to change because you're not using any of the placement elements,top, right, bottom, left.

    absolute takes an element out of its normal flow for manual positioning. So with this you can overlap elements. Or even make an element move half way out of its container then use the overflow property to display the element with scrollbars or whatever.

    Sorry, this is the best example I can come up with. If someone can share a site where I can type example code in and have it display its output on the same page I would appreciate it. I want to show a clear examples of this.

    Hope this helps! Let us know how you're doing

    :showoff:

    reference:
    The Box Model
    Overflow Property

    source:
    codeschool.com (css cross country course)

  5. #4
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    There is a good explanation of the various types of positioning HERE

    You can go HERE to try it for yourself.
    yianna talantios and Reza O like this.
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  6. #5
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    http://www.jsfiddle.com/ <-- here you go, Yianna.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  7. #6
    Junior Member yianna talantios's Avatar
    Join Date
    Dec 2012
    Posts
    14
    Member #
    34278
    Quote Originally Posted by AlphaMare, post: 245758
    There is a good explanation of the various types of positioning HERE

    You can go HERE to try it for yourself.
    what a great read! I'm reading the articles he linked in that main article as well. Thanks! It's nice to get a truly deep understanding of it.

  8. #7
    Junior Member yianna talantios's Avatar
    Join Date
    Dec 2012
    Posts
    14
    Member #
    34278
    aahhhhh HA!!!! So any elements that are being positioned absolutely within it's containing\parent element will be positioned in relation to it. If there is no relation then they will position themselves outside of the containing element and stick to the browser size instead. nothing is containing them =D

    http://css-tricks.com/absolute-posit...e-positioning/

  9. #8
    Junior Member adibir's Avatar
    Join Date
    Nov 2012
    Location
    LA
    Posts
    7
    Member #
    33899
    we have 3 kind of positioning ,

    1) Normal Document Flow
    -: Static = Default
    -: Relative : you can offset the elements with coordination and they will NOT remove from "normal Document Flow"

    2)Absolute

    -: Absolute : you can offset the elements with coordination and they will remove from "normal Document Flow" and They will offset related to their nearest Positioned Parent ( looks for the first parent that have position attribute -- ( that's why you see a parent element that have only position set to "relative" with no coordination) )

    -: Fixed : elements are offsetting and removed from "normal document flow" and doesn't care about their parent's position and always are relative to the viewport .

    3)float : just removes from "normal document flow" and floats to left -right

    i hope you undrestood

  10. #9
    WDF Staff AlphaMare's Avatar
    Join Date
    Oct 2009
    Location
    Montreal, Canada
    Posts
    4,570
    Member #
    20277
    Liked
    878 times
    Quote Originally Posted by TheGAME1264, post: 245763
    http://www.jsfiddle.com/ <-- here you go, Yianna.
    HUH? Attachment 2643
    Attached Images Attached Images
    Good design should never say "Look at me!"
    It should say "Look at this." ~ David Craib


    http://digitalinsite.ca ~ my current site . . info@digitalinsite.ca ~ my email

    If you feel that someone's post helped you fix your problem, answered your question, or just made you feel better, feel free to "Like" their post. The "Like" link is at the bottom right of each post, along side the "reply" link. And if you are being helped here, try to help someone else - pass it on!

  11. #10
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    Whoops...meant http://jsfiddle.net/ .
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 09:30 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com