css - 背景大小为 'changing image link/on hover' + 文本定位的问题

标签 css

我似乎无法正确设置图像链接的高度和宽度,而且我无法在不移动整个背景的情况下将文本向下移动。

I created a jsFiddle to show what I mean

我希望左侧的最终链接看起来像右侧的“链接”,但尚未设置。

这是我的代码:

<p class="x"><a href="#">All Events</a></p>

.x a {
    color: #FFFFFF;
    text-decoration: none;
    text-indent:50px;
    font-weight: bold;
    background-image: url('http://i.imgur.com/TGhDs.png');
    background-position: center 0px;
    background-repeat: no-repeat;
}

.x a:hover {
    color: #8dcdff;
    text-decoration: none;
    padding-left: 0px;
    font-weight: bold;
    background-image: url('http://i.imgur.com/TGhDs.png');
    background-position: center -21px;
    background-repeat: no-repeat;
}

同样有趣的是,在我的电脑上,相同的代码和一切看起来像这样: enter image description here

这是为什么?谢谢:)

最佳答案

这是一种方法。 http://jsfiddle.net/jalbertbowdenii/pmh9f/

Sprite 就是这么棘手。如果这还不够好,还有其他各种方法。

关于css - 背景大小为 'changing image link/on hover' + 文本定位的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7705464/

相关文章:

html - 如何为 IE 设置边框不透明度?

html - 如何将任意大小的图像放在框架中间

html - CSS 无法识别来自 div 标记的标识符 (ID)。

jquery - 通过 CSS 类淡出 "Hidden"的 HTML 元素

html - div 之前的 CSS 形状

javascript - 默认情况下,如何使容器中的滚动从某个链接开始?

html - 如何使用多属性 css 变量?

JavaScript,迭代类并单击显示隐藏的 tr

html - Bootstrap入门关于重写样式的问题

javascript - 弹出窗体 - 定位和样式