2016-11-16 65 views
-3

我正在嘗試使用CSS sprites移動圖像的特定部分上的一段文字。但我應用的背景位置似乎不起作用。我試圖改變背景位置,但文本部分(即twitter,臉書)不移動到正確的位置。 I am using this image i want second raw circle social icon如何正確使用css sprite?

#fixedsocial { 
 
\t background:url("../img/socials/icon.png") no-repeat;   
 
    top:40%;  
 
    width:50px; 
 
    height: 100px; 
 
    position:fixed; 
 
    left: 0; 
 
    display: block; 
 
    z-index: 1000; 
 
    background-color: #eee; 
 
    text-indent:-9999px; 
 
} 
 

 
.facebookflat { 
 
    background-position: -200px 0; 
 
    height:50px; 
 
} 
 

 
.facebookflat:hover {   
 
\t cursor: pointer; 
 
} 
 

 
.twitterflat {  
 
\t height:50px; 
 
\t background-position: -400px 0; 
 
} 
 

 
.twitterflat:hover {  
 
\t cursor: pointer; 
 
}
<div id="fixedsocial"> 
 
    <div class="facebookflat" id="shareBtn"></div> 
 
    <div class="twitterflat"> <a href="https://twitter.com/share" data-show-count="false"></a> </div> 
 
</div>

+0

其實我不明白您的要求。 – ketan

+0

我想顯示出現在第二排圓圈上的Facebook和Twitter圖標 –

+0

「**我想要顯示在第二排圓圈上出現的Facebook和Twitter圖標**」這是什麼意思? – ketan

回答

0

它不工作的原因是,你的背景圖像分配到容器DIV(#fixedsocial),並嘗試調整在內部div的定位,其中有沒有背景的位置。你需要重新思考你的CSS,因爲你必須指定你真正想要使用它的背景。

這裏有一個小提琴:https://jsfiddle.net/j7kyhgmc/

#fixedsocial { 
 
top:40%;  
 
width:50px; 
 
height: 100px; 
 
position:fixed; 
 
left: 0; 
 
display: block; 
 
z-index: 1000; 
 
background-color: #eee; 
 
} 
 

 
.facebookflat { 
 
background: url("https://i.stack.imgur.com/LR6bK.png") no-repeat; 
 
background-position: -168px -161px; 
 
background-size: 1430% 1430%; 
 
height:50px; 
 
width: 50px; 
 
} 
 

 
.facebookflat:hover {   
 
    cursor: pointer; 
 
    } 
 

 
    .twitterflat {  
 
background: url("https://i.stack.imgur.com/LR6bK.png") no-repeat; 
 
background-position: -430px -161px; 
 
background-size: 1420% 1420%; 
 
height:50px; 
 
width: 50px; 
 
    } 
 

 
    .twitterflat:hover {  
 
     cursor: pointer; 
 
    }
<div id="fixedsocial"> 
 
    <div class="facebookflat" id="shareBtn"></div> 
 
    <div class="twitterflat"> 
 
      <a href="https://twitter.com/share" data-show-count="false"></a> 
 
    </div> 
 
</div>

+0

你能幫我嗎? –

+0

添加了一個示例。由於您的'50px * 50px'框對於原始圖像尺寸太小,所以我不得不插入'background-size'。如果你想使圖標看起來不錯,你可以調整原始圖像的大小,或者稍大一些的框(然後丟失'background-size'屬性,並且可能不得不使用'background-position'重新對齊圖標 - – junkfoodjunkie

+0

是的,它的工作 –