使用图像作为通用链接背景
我怎样才能将图像作为所有链接的背景?我想要一个漂亮的盒子来代表按钮,但我无法弄清楚这一点。
我已经尝试过:
a {
font-size: 40px;
background: url('images/shooting-stars/shooting-star-link.png') no-repeat left top;
}
但这不起作用,图像未显示。
How can I do to have an image as the background for all links? I want to have a nice box representing buttons, but I cannot figure this out.
I have tried:
a {
font-size: 40px;
background: url('images/shooting-stars/shooting-star-link.png') no-repeat left top;
}
But this is not working, image is not displaying.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“我想要一个漂亮的盒子来代表按钮,但我无法弄清楚这一点。” - 我不明白这部分。
不管怎样,你的 css 从这里看起来很好,你确定图像存在吗?这是一个具有完全相同代码的工作示例,只是我确定存在的图像:
http://jsfiddle.net /3k9nm/
如果你想始终显示图像,即使文本较短,你也应该设置链接的最小宽度。这确实意味着它们必须是内联块,您不能在常规链接(这是内联元素)上设置宽度。
(25px是随机选择的,填入你背景图片的宽度..)
"I want to have a nice box representing buttons, but I cannot figure this out." - I don't understand this part.
Anyway, your css looks fine from here, are you sure the image exists? This is a working example with the exact same code, just an image that I'm sure exists:
http://jsfiddle.net/3k9nm/
If you want to always show the image, even if the text is shorter, you should set a minimum width for the links. This does mean they'll have to be inline-blocks, you can't set width on a regular link (which is an inline element).
(25px was randomly chosen, fill in the width of your background image..)
要尝试两件事,实际的
链接中是否有任何文本?如果您使用 Firebug,您可以检查您是否确实获得了图像的正确文件路径...
Two things to try, is there any text in the actual
<a>
links? And if you use Firebug, you can check you've definitely got the right file path to the image...HTMLCSS
HTML
CSS