除非 <a 有空格,否则 css 不显示图像

标签 css

我有几个用于评级系统的 css Sprite :http://i.imgur.com/qeb2b.png

加载缩略图时

 .thumb-down {
    background: url('http://i.imgur.com/qeb2b.png') no-repeat -126px -13px;
    width: 15px;
    height: 16px;
 }

 .thumb-up {
    background: url('http://i.imgur.com/qeb2b.png') no-repeat -126px -33px;
    width: 15px;
    height: 16px;
 }

让大拇指出现的唯一方法是这样做:

Was this review helpful? <a href="#" class="thumb-up rating">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a> | <a href="#" class="thumb-down rating">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>

如果我删除所有 &nbsp;然后大拇指消失了。如果我只留下一个&nbsp;然后它显示 Sprite 的局部 View 。

如何在不需要 &nbsp;? 的情况下显示 Sprite ?

最佳答案

通过使用float:left:

 .thumb-down {
    background: url('http://i.imgur.com/qeb2b.png') no-repeat -126px -13px;
    width: 15px;
    height: 16px;
    float: left;  /* OR float:right, depending on what you need */
 }

 .thumb-up {
    background: url('http://i.imgur.com/qeb2b.png') no-repeat -126px -33px;
    width: 15px;
    height: 16px;
    float: left;
 }

关于除非 <a 有空格,否则 css 不显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10879027/

相关文章:

html - 如何将固定位置元素放在相对定位元素之上?

html - 如何使用 CSS 禁用 div 容器中的不透明度?

html - HTML 表格仍然可行吗?

jquery - jQuery 是否将 CSS3 用于动画?

html - 如何显示与标题内联的链接?

HTML CSS 响应式卡片

css - 如何在 asp.net 后面的 .ashx.cs 代码中添加 css

html - 在 href 之后给予焦点

javascript - 如何制作可以在单元格中搜索多个值的表格过滤器?

php - 放置一个 HTML 表格,使行索引 X 位于标题正下方的显示顶部