把跨度放在div的顶部

时间:2015-04-18 10:57:33

标签: html css html5 css3

我用计数器构建了一些社交按钮。我希望计数器数据显示在我的按钮之上。不知何故,他们总是在按钮内。

  1. 是否可以将按钮数量放在按钮顶部,怎么样?

  2. 每个社交按钮都有文字,即使我放了float: lefttext-align: left,文字仍显示在中心,为什么?

  3. 请看我的小提琴... Fiddle

    我的HTML:

    <a class="post-share facebook entShare" target="entsharewindow" href="#">
    <div class="social-buttons-text">Facebook Like</div><span>0</span>
    </a> 
    <a class="post-share facebook entShare" target="entsharewindow" href="#">
    <div class="social-buttons-text">Facebook Share</div><span>0</span>
    </a> 
    <a class="post-share twitter entShare" target="entsharewindow" href="#">
    <div class="social-buttons-text">Twitter</div><span>0</span>
    </a> 
    

    我的CSS:

     a.post-share {
        display: block;
        width: 74px;
        height: 34px;
        float: left;
        margin: 10px 0px 0px 0px;
        background: #3e599a url(sidebar-share.png) no-repeat 0 0;
        text-decoration:none;
        width: 110px;
        text-indent: 50px;
        font: 15px/46px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
        color: #FFFFFF;
    }
    a.post-share:hover {
        opacity: 0.8;
        text-decoration: none;
        cursor: pointer;
    }
    
    a.post-share span {
        width: 22px;
        height: 18px;
        padding: 3px;
        display: block;
        float:right;
        background-color:#080563;
        color: #FFFFFF;
        font-style:bold;
        vertical-align: middle;
        font: 10px "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
        text-align:center;
        text-indent: 0;
    }
    
    a.post-share.facebook {
    background-color: #3B5998;
    background-image: url('/images/social-icons/facebook-32.png');
    margin-right: 10px;
    }
    
    a.post-share.facebook {
    background-color: #3B5998;
    background-image: url('/images/social-icons/facebook-32.png');
    margin-right: 10px;
    }
    
    
    a.post-share.googleplus {
    background-color: #D14836;
    background-image: url('/images/social-icons/googleplus-32.png');
    margin-right: 10px;
    }
    
    .social-buttons-text {
        font-size:4px;
        color:#FFFFFF;
        float:left;
        margin:0px;
        padding:0px;
        text-align:left;
    }   
    

1 个答案:

答案 0 :(得分:2)

  • 您可以设置a代码position:relativespan内的position:absolute,并topleft将其与position对齐1}}

a.post-share {
  display: block;
  width: 74px;
  height: 34px;
  float: left;
  margin: 40px 0px 0px 0px;
  background: #3e599a url(sidebar-share.png) no-repeat 0 0;
  text-decoration: none;
  width: 110px;
  font: 15px/46px"Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
  color: #FFFFFF;
  position: relative;
}
a.post-share:hover {
  opacity: 0.8;
  text-decoration: none;
  cursor: pointer;
}
a.post-share span {
  width: 22px;
  height: 18px;
  padding: 3px;
  display: block;
  position: absolute;
  top: -24px;
  right: 0;
  background-color: #080563;
  color: #FFFFFF;
  font-weight: bold;
  vertical-align: middle;
  font: 10px"Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
  text-align: center;
  text-indent: 0;
}
a.post-share.facebook {
  background-color: #3B5998;
  background-image: url('/images/social-icons/facebook-32.png');
  margin-right: 10px;
}
a.post-share.facebook {
  background-color: #3B5998;
  background-image: url('/images/social-icons/facebook-32.png');
  margin-right: 10px;
}
a.post-share.googleplus {
  background-color: #D14836;
  background-image: url('/images/social-icons/googleplus-32.png');
  margin-right: 10px;
}
.social-buttons-text {
  font-size: 4px;
  color: #FFFFFF;
  float: left;
  margin: 0px;
  padding: 0px;
  text-align: left;
}
<a class="post-share facebook entShare" target="entsharewindow" href="#">
  <div class="social-buttons-text">Facebook Like</div><span>0</span>
</a>
<a class="post-share facebook entShare" target="entsharewindow" href="#">
  <div class="social-buttons-text">Facebook Share</div><span>0</span>
</a>
<a class="post-share twitter entShare" target="entsharewindow" href="#">
  <div class="social-buttons-text">Twitter</div><span>0</span>
</a>