SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Absolute postioning in a div

    Hi!

    I need to postion a span element absolute IN a div. My markup is:
    Code:
    <div>
       <span></span>
       <span></span>
    </div>
    I want to control the margin betwen the left sides of the spans and the left side of the div. For example: I want span nr 2 to be 50px into the div and span nr 1 to be 20px into the div.

    One way is to set the span nr 2 left margin to:
    left to div - left margin on span nr 1

    Hope you understand what I mean

    Thanks!
    Martin

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    CSS:
    Code:
    div span#one {
      position:absolute;
      left:20px;
      top:0;
    }
    div span#two {
      position:absolute;
      left:50px;
      top:0;
    }
    HTML Code:
    <div>
       <span id="one"></span>
       <span id="two"></span>
    </div>

  3. #3
    SitePoint Wizard bronze trophy Tyssen's Avatar
    Join Date
    Oct 2005
    Location
    Brisbane, QLD
    Posts
    4,067
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't really need to specify div in front of span#one because an ID can only refer to one element so it doesn't matter what its parents are (unless you're referring to elements that have different parents on different pages).

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Tyssen speaks the truth.

    Even though it's redundant, I still do it sometimes, I think it helps me to sometimes know what the parent element is from looking at the CSS.

  5. #5
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Now im feeling a little bit stupid.. :P
    I tried that and I promise you it didn't work before
    But thank you so much!
    I'm making a slider widget and use this markup for the track and the handlers.

    Thanks again!


Bookmarks

Posting Permissions

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