How can I display social icons on my website with HTML and CSS?

拥有回忆 提交于 2019-12-06 11:00:27

I would create an image sprite for my icons. And then for the markup I would use a list and set the icon images as background images to their respective anchor tags... Something like this...

HTML

<ul>
<li><a href="" class="icon facebook">Facebook</a></li>
<li><a href="" class="icon twitter">Twitter</a></li>
<li><a href="" class="icon googleplus">Google Plus</a></li>
</ul>

CSS

ul li {
float:left;
display:block;
}

.icon {
width:25px;
height:25px;
display:block;
text-indent:-9999px;
background-image:url(http://tridentdesign.com/wp-content/uploads/2012/12/gemicon.jpg);
background-repeat:no-repeat;
}

.facebook {
background-position:-140px -115px;
}
.twitter {
background-position:-185px -115px;
}
.googleplus {
background-position:-140px -265px;
}

HERE IS A FIDDLE TO DEMONSTRATE:

http://jsfiddle.net/Z8zkK/2/

Edit: I updated my css to match my fiddle.

When you are adding an image in CSS you should add atleast Height or width, it's good to add both, you can ignore(not necessarily) when you are adding images using img tag.

To get in inline, as you are using div, add float:left to .icons class

 .icons {
  margin-left:30px;
  float:left;
  width:50px;
  height:50px;
  }

You can also use the answer by Kris Hollenbeck, in that case you have to rewrite you HTML code too, which is highly preferred.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!