如何制作 CSS 翻转图像? (精灵)
我只是想用我在一本网页设计杂志上看到的这个小技巧来制作一些图像翻转,但我遇到了一点麻烦。我的尝试是一次可怕的失败,哈哈。我只想看到上半部分(42 像素高),然后翻转时的下半部分(显然是-42 像素)
宽度也是 42 像素。有人可以写一些东西来实现这一点吗? 图像: http://img826.imageshack.us/img826/6568/homebi.png
I'm just trying to use this little trick I saw in one of my web design magazines to make a little image rollover but I'm having just a small bit of trouble. My attempt was a terrible fail lol. I just want to see the top half (42px tall) and then the bottom half on rollover (-42px obviously)
width is also 42px. Could someone write something up to make that happen?
image:
http://img826.imageshack.us/img826/6568/homebi.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这一切都与
background-position
的初始值(非:hover
)和最终值(:hover
)有关。演示
根据您的评论:用锚点包装
(
),具体操作如下:
替换为
。这是因为锚点的有效子元素必须是内联元素
display: inline-block
。演示 2
It's all about the initial (non-
:hover
) and final (:hover
) values ofbackground-position
.Demo
As per your comment re: wrapping the
<div>
with an anchor (<a>
), here's what to do:<div>
out for a<span>
. This is because valid children of anchors must be inline elementsdisplay: inline-block
on the span.Demo 2
试试这个:
Try this:
这是图像翻转的基本框架。
css
html
重要的部分是背景位置,在按钮上正常状态设置为“顶部”,当您鼠标悬停时背景位置为“底部”。
假设包含两个按钮状态的图像的高度为 84 像素,这样就可以正常工作。
Heres the bare bones for an image rollover.
the css
The html
The important part is the background position, which on the buttons normal state is set to 'top', when you rollover the background postion is 'bottom'.
Assuming your image which contains both button states is 84px high this will work fine.