Adding icon image to css class for html elements

Try this

.ico:after{
    content: '';
    display: block;
    height: 40px;  /*height of icon */
    width: 40px;  /*width of icon */
    position: absolute;
      /*where to replace the icon */
    top: 0px;
    left: -40px;
      /*background */
    background: #F8E6AE url(ico.gif) no-repeat 0px 0px;
}

You can do this in a very simple way! Just wrap the Icon inside the <a> tag instead of giving the <a> tag the class of the Icon:

<a href="#"><i class="fas fa-icon"></i>Email Link</a>

I'm using the fas fa-icon class to represent the use of the fontawesome library, you must specify your own icon. Here's another smart tip for you to use in the <a href=""> tag: Add mailto and then the mail you want to send a mail to. Example:

<a href="mailto:[email protected]"><i class="fas fa-icon"></i></a>

This opens the default mail application on the computer with the receiver already filled in as '[email protected]'!


You can do that using pseudo elements

.ico{
    width:100px;
    display:block;
    height:20px;
    background:black;
    color:white;
    text-decoration:none;
    padding-left:20px;
}
.ico:before{
    content: '';
    background:url('https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSj3XfIpf-OOJRCcWz4iN2CU3qMKVVbj0p0bRvKNGVo1U9pk_8ZIlyR8pWreA');
    background-size:cover;
        position:absolute;
    width:20px;
    height:20px;
    margin-left:-20px;
}
 <a href="#" class="ico">Email Link</a>
 <a href="#" class="ico">Another Link</a>

Tags:

Html

Css