我用计数器构建了一些社交按钮。我希望计数器数据显示在我的按钮之上。不知何故,他们总是在按钮内。
是否可以将按钮数量放在按钮顶部,怎么样?
每个社交按钮都有文字,即使我放了float: left
和text-align: left
,文字仍显示在中心,为什么?
请看我的小提琴... 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;
}
答案 0 :(得分:2)
a
代码position:relative
及span
内的position:absolute
,并top
和left
将其与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>