html - 使用文本缩进保持背景图像到位

标签 html css

我在 <div> 中有以下 html :

<span class="footer-icons">
    <a href="#;" class="facebook" title="Facebook">Facebook</a>
    <a href="#;" class="twitter" title="Twitter">Twitter</a>
</span>

还有我的 CSS:

#footer .footer-icons {
    float: right;
    margin-right: 10px;
}
#footer .footer-icons {
    text-indent: -9999px;
}
#footer .footer-icons .facebook {
    background: url("../images/new/footer-icons.png");
}

问题在于 text-indent导致背景图像也移动。我如何才能做到“转义文本”(例如,使用文本缩进:-9999px)并保持背景图像不变?

最佳答案

这是工作 fiddle :http://jsfiddle.net/surendraVsingh/qdFNM/5/ (更新)

添加 display:inline-block 并为该 div 指定与图像相同的宽度和高度。

CSS

.footer-icons {
    margin-right: 10px;
}
.footer-icons {
    text-indent: -9999px;
}
.footer-icons .facebook {
    background: url("https://dl.dropbox.com/u/19982181/fab/fb.jpg") no-repeat left top ;
    width:20px; height:20px;
    display:inline-block;
}
.footer-icons .twitter {
    background: url("https://dl.dropbox.com/u/19982181/fab/tw.jpg") no-repeat left top ;
    display:inline-block;
    width:20px; height:20px;
}

关于html - 使用文本缩进保持背景图像到位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11272325/

相关文章:

jquery - 使用视口(viewport)单位的响应式设计中的 CSS 文本溢出

javascript - 使用 CSS 和 JS 的双语网站是一个坏主意吗?

html - 3 列 - 带溢流元件的中心列流体

html - 如何向导航栏的每个 "section"添加文本?对于首页 x 文本显示,对于历史 : y text shows?

html - 粘性页脚冲突 css

javascript - JQuery 工具提示自定义悬停元素以显示在图像 map 上方

html - 我应该如何对齐忽略同一级别 float <div> 的文本?

PHP 无法添加或更新子字段 - 外键错误

html - 如何在点击时在 A4 页面内打印大小票据?

jquery - 如何映射取决于内容的高度?