treehouse : what would you like to learn today?
Web Design Web Development iOS Development

Rounded Corner Mystery

  • This might seem like a dumb question to some but I´m baffled.

    In Chris´ tutorial on 'Rounded Corners' I have noticed something in the second example of the five techniques that is interesting.

    This is the code from the tutorial:

    <div class=\"box-two\">
    <div class=\"inside\">
    <p>Lorem ipsum dolor</p>
    </div>
    <div class=\"tl\"></div>
    <div class=\"tr\"></div>
    <div class=\"bl\"></div>
    <div class=\"br\"></div>
    </div>


    And the css...

    .box-two { width:300px; background:#fbeac3; border:1px solid #534515; position:relative; margin:10px 0 }
    .box-two .tl { position:absolute; etc. etc. }
    .box-two .tr { position:absolute; etc. etc. }
    .box-two .bl { position:absolute; etc. etc. }
    .box-two .br { position:absolute; etc. etc. }
    .box-two .inside { padding:20px }


    Now my question:
    Why is it, that by just giving the corner divs a position of "absolute", does it make them 'pop' into place in four different corners?

    After all, there is a div with a class of "inside" that is marked up before the divs that form the corners.
    How do they manage to scatter all-around the "inside" div like that?

    I´d love to understand this becuase I´ve been doing rounded corners the hard way it seems.

    Thanks!
  • When you give any page element a position of absolute, it is removed from the normal flow of the document (it's not affected by other page elements and other page elements don't affect it). It gets placed precisely where you put it, and the coordinates are relative to the closest parent above it with relative positioning. In this case, it's the <div class="box-two"> which has the relative positioning. So the four divs are placed in the top right, top left, etc of that box.

    To learn a little more about how this absolute positioning this is used here:
    http://css-tricks.com/absolute-position ... sitioning/
  • Mmm... that is very interesting Chris.

    Thanks for the explanation - I understand it much better now.