CSS Hide Text But Show Image?

前端 未结 4 977
北荒
北荒 2021-02-02 10:04

I need to change something without touching HTML codes.

So I have this code in my HTML

 
    
  • Sha
相关标签:
4条回答
  • 2021-02-02 10:23

    You could use text-indent:

    text-indent: -9999px; /* get rid of any text */
    
    0 讨论(0)
  • 2021-02-02 10:25

    Try making your font-size : 0px; in your css.

    0 讨论(0)
  • 2021-02-02 10:26

    Make the text transparent. Since it's a link, you'll want to use a few selectors to make sure all cases are addressed:

    .twitter a, .twitter a:link, .twitter a:visited
    {
        color: transparent;
    }
    

    Edit: This other option, while more verbose, has the benefit of keeping the focus border (the little dots that appear when a link is selected) to the size and shape of the twitter icon. Also, the text will not be revealed if selected and copied and pasted. It becomes invisible and unselectable. Here is the technique:

    .twitter a {
        display: inline-block;
        overflow: hidden;
        width: 0;
        height: 14px;
        padding-left: 10px;
    }
    
    0 讨论(0)
  • 2021-02-02 10:35

    use text-indent with a little magic in it :)

    HTML:

               <span class="share"> 
                    <ul>
                        <li>Share &nbsp;&nbsp;</li>
                        <li class="twitter"><a href="#" class="twitter">twitter</a></li>
                        <li class="facebook"><a href="#">facebook</a></li>
                        <li class="delicious"><a href="#">delicious</a></li>
                        <li class="friendfeed"><a href="#">friendfeed</a></li>
                        <li class="addthis"><a href="#">share</a></li>
                        <div class="clear"></div>
                    </ul>
                </span>
    

    CSS:

    a.twitter {
        background-image:url('../images/tt.png');
        display:block;
        height:58px;
        text-indent:-9999px;
        width:200px;
    }
    

    So you see the text is indented but still the image is still clickable because i've put a class in the twitter link ;)

    0 讨论(0)
提交回复
热议问题