2011-05-18 99 views
0

由於可能能夠在此的jsfiddle例子來看看,我想獲得的評論(12中的例子)數的計數顯示爲文本在註釋氣泡圖像:如何將評論數作爲文本顯示在評論泡泡圖像上?

http://jsfiddle.net/c337Z/

HTML:

 <ul id="top"> 
      <li><a href="/comments"><div id="commentlink">12</div></a></li> 
     </ul> 

CSS:

#commentlink 
{ 
    background: url("http://cdn1.iconfinder.com/data/icons/DarkGlass_Reworked/128x128/actions/kopetestatusmessage.png") no-repeat 0 0; 
    width:128px; 
    height:128px; 
} 

的想法是用戶能夠看到有多少意見存在和然後點擊泡泡圖像被重定向到評論頁面。

但是,文本顯示在圖像的左側,而不是圖像中間的死點。

我需要做些什麼來讓文字出現在圖像的中心?

回答

0

我認爲這是你在找什麼:http://jsfiddle.net/75JsT/

+2

如果@Tarosh只希望在泡泡中放置一個#,這個解決方案很好。當存在多行內容時,使用'line-height'可以使內容擴展出泡泡。 – 2011-05-18 15:02:33

2

嵌套一個DIVA裏面是不是有效的標記。

嘗試......

演示:http://jsfiddle.net/wdm954/c337Z/5/

HTML ...

<ul id="top"> 
    <li> 
     <a href="/comments" class="commentlink">12</a> 
    </li> 
</ul> 

CSS ...

.commentlink { 
    display: block; 
    background: url("http://cdn1.iconfinder.com/data/icons/DarkGlass_Reworked/128x128/actions/kopetestatusmessage.png") no-repeat 0 0; 
    width:128px; 
    height:128px; 
    text-align: center; 
    padding-top: 40px; 
} 
+0

在'A'內嵌入'div',它在HTML 5中有效:) – 2011-05-19 04:41:49

0

您可以自定義/刪除櫃檯上的梯度,並設置使用的「counterField」的innerHTML計數器的值見這個例子http://jsfiddle.net/3czxB/2/

<div id="noti_Container"> 
    <img height="48" width="48" src="http://cdn1.iconfinder.com/data/icons/DarkGlass_Reworked/128x128/actions/kopetestatusmessage.png" /> 
    <div id="counterField" class="noti_bubble">1000</div> 
</div> 

,這使得它的工作/漂亮(在IE不是很大的CSS )

 #noti_Container { 
      position:relative; 
      border:1px solid blue; 
      width:48px; 
      height:48px; 
     } 

     .noti_bubble { 
      position:absolute; 
      top: 10px; 
      right:10px; 
      padding:1px 2px 1px 2px; 
      background: rgb(255,175,75); /* Old browsers */ 
      background: -moz-linear-gradient(top, rgba(255,175,75,1) 0%, rgba(255,146,10,1) 100%); /* FF3.6+ */ 
      background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(255,175,75,1)), color-stop(100%,rgba(255,146,10,1))); /* Chrome,Safari4+ */ 
      background: -webkit-linear-gradient(top, rgba(255,175,75,1) 0%,rgba(255,146,10,1) 100%); /* Chrome10+,Safari5.1+ */ 
      background: -o-linear-gradient(top, rgba(255,175,75,1) 0%,rgba(255,146,10,1) 100%); /* Opera 11.10+ */ 
      background: -ms-linear-gradient(top, rgba(255,175,75,1) 0%,rgba(255,146,10,1) 100%); /* IE10+ */ 
      background: linear-gradient(to bottom, rgba(255,175,75,1) 0%,rgba(255,146,10,1) 100%); /* W3C */ 
      filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffaf4b', endColorstr='#ff920a',GradientType=0); /* IE6-9 */ 
      border: 1px solid gray; 
      color:white; 
      font-weight:bold; 
      font-size:0.65em; 

      border-radius:30px; 
      box-shadow:1px 1px 1px gray; 
     }