.social-media-icon{
display: inline-block;
}
.social-media-icon a{
text-decoration: none;
display: block;
text-indent: -9999px;
border: 2px solid #c3d4e2;
position: relative;
height: 36px;
width: 36px;
background: url(/img/social-icons.png) ;
background-repeat: no-repeat;
background-position: 50%;
}
.social-media-icon a:hover{
background-color: #c3d4e2;
}
.fb-icon a{
background-position: 0 0 ;
}
.fb-icon a:hover{
background-position: 0 -36px;
}
.x-icon a{
background-position:-36px 0 ;
}
.x-icon a:hover{
background-position: -36px -36px ;
}
.youtube-icon a{
background-position: -72px 0 ;
}
.youtube-icon a:hover{
background-position: -72px -36px ;
}
.insta-icon a{
background-position: -108px 0 ;
}
.insta-icon a:hover{
background-position: -108px -36px ;
}
<div class="social-media">
<div class="fb-icon social-media-icon icon">
<a href="">
<span class="social-text">fb</span>
</a>
</div>
<div class="x-icon social-media-icon icon">
<a href="">
<span class="social-text">x</span>
</a>
</div>
<div class="youtube-icon social-media-icon icon">
<a href="">
<span class="social-text">youtube</span>
</a>
</div>
<div class="insta-icon social-media-icon icon">
<a href="">
<span class="social-text">intergram</span>
</a>
</div>
This code snippet is for creating background images using image sprites. when hovering over the image that background image should change.
I want to center those social media icons in that div
element. I tried background-position: center center
but it didn’t work. Here I attached an output of the above code snippet. That isn’t centered properly. What can I do to center all images in each div elements
2
Answers
Here is a better way to code is using more generic values but you may have to edit the image because the icons inside the image aren’t perfectly centered. it’s not a CSS issue.
You need to adjust the
background-position
for all the icons.