Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS How to set a css property to an inner element relative to the outer element?

  • This topic is empty.
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #45677
    jiddisch
    Member

    #This is the HTML:

    #This is the CSS:

    ul {
    background: gray;
    width: 50px;
    }
    ul li a.active {
    border-right: 1px solid red;
    }

    I want the red border of the ‘active’ element to be shown outside the box on a fixed position (no metter the length of the ‘a’ element).

    It’s on a CMS and I don’t have control to move the ‘active’ class to the ‘li’ element. How can I do it with this markup?

    http://jsfiddle.net/7fdMh/

    #139461
    wolfcry911
    Participant

    ul a { display: block;}

    #139515
    jiddisch
    Member

    Thank You!
    And if I want to place the little red border a few pixels outside the box, what do I need to do?

    #139516
    daffy58
    Participant

    Give it a little trick with white border of anchor tag

    ul a { display:block; border-right: 1px solid #fff;}

    #139523
    Sarfaraj
    Participant
    #139527
    TheDoc
    Member

    Just another little note: I actually prefer to put the active class on the outer most element, in this case the `

  • `. If you need to target the `
  • ` of an active link with your method, you’re unable to. Just something to think about!
#139528
Sarfaraj
Participant

ul {
background: gray;
width: 50px;
}
ul li a.active {
border-right: 1px solid red;
display:block;
}

#139553
JTParrett
Participant

You could give all the other anchors a white border, making the red border seem as if it’s outside of the ul. Or you could give the anchors a gray background instead of the ul and then give the anchors a transparent border, so that the whole section can be placed on any colour background and the effect will still apply. I hope that makes sense :P

http://jsfiddle.net/Jb6W6/

#139574
Paulie_D
Member
#139587
wolfcry911
Participant

simply give the anchor width: 100% and the border will render outside the li

#139622
jiddisch
Member

Thank You all!
especially to wolfcry911.

Viewing 11 posts - 1 through 11 (of 11 total)
  • The forum ‘CSS’ is closed to new topics and replies.