Forums

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

Home Forums CSS Image with :after issue

  • This topic is empty.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #33738
    Nigel
    Member

    I have a background image using :after but it wont appear unless I use content to add text. Is there another way?

    #84304
    jamygolden
    Member

    The ‘content’ property is required.

    Do this:

    div:after{content: '';}
    #84305
    shazdeh
    Member

    I don’t remember why, but I read somewhere that content: "020"; is better. Does anyone has any info on this?

    #84310
    Chris Coyier
    Keymaster

    Empty value is fine.

    #84318
    Nigel
    Member

    Sadly your suggest are not working. I also noticed something else while working on it. The image gets cut off even though it has plenty of room. All my code over the weekend was going so smoothly too :/

    #84331

    Does it have a defined height and width? Please post some code so that we can further assist you.

    #84352
    Nigel
    Member
    #nav li:after{
    background : url(../images/bon-end.png) no-repeat;
    content : "";
    }

     

    The li tag already has a defined height and width. I tried setting a height/width in the after but it did nothing.

    #84336
    jamygolden
    Member

    Do this:

    #nav li:after{
    content : url(../images/bon-end.png);
    }

    If you want to specifically use the background property, you will have to set a width and height to the pseudo element the same way you’d have to set it on a normal element.

    #84356
    Nigel
    Member

    This works(thanks!) but it adds two. I used chrome to inspect the element and it adds an extra LI tag after the first one so now it will draw two images instead of one. The only fallback I know is to hard code a navigation with images but that’s not very good :/

    #84362
    OniLinkCR
    Member

    You need to declare the LI as relative and then use the after as absolute and use positioning to place it.



    #nav li {position:relative;}

    #nav li:after {position:absolute; content:''; top:yourvalies; left:yourvalues; background:"url" height:"valeue"; width:"value";

    #84381
    jamygolden
    Member

    You don’t necessarily need to need to declare it as absolute. If it’s adding a new li in firebug, I’d bet it’s got to do with your markup. Try validating the page.

    Also, is there a reason you are avoiding background images?

    #282275
    Manoj Sharma
    Participant

    I have just applied this CSS and its done

    #nav li:after{ content: ”;
    height: 30px;
    width: 30px;
    background: url(../images/thumb-pin.png) no-repeat;
    position: absolute;
    margin-left: -10px;
    background-size: 21px;
    margin-top: 6px;
    }

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