使用图像作为通用链接背景

发布于 2024-10-16 17:28:23 字数 233 浏览 3 评论 0原文

我怎样才能将图像作为所有链接的背景?我想要一个漂亮的盒子来代表按钮,但我无法弄清楚这一点。

我已经尝试过:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ˉ厌 2024-10-23 17:28:23

“我想要一个漂亮的盒子来代表按钮,但我无法弄清楚这一点。” - 我不明白这部分。

不管怎样,你的 css 从这里看起来很好,你确定图像存在吗?这是一个具有完全相同代码的工作示例,只是我确定存在的图像:

http://jsfiddle.net /3k9nm/

如果你想始终显示图像,即使文本较短,你也应该设置链接的最小宽度。这确实意味着它们必须是内联块,您不能在常规链接(这是内联元素)上设置宽度。

a {
  display: inline-block;
  min-width: 25px;  
}

(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).

a {
  display: inline-block;
  min-width: 25px;  
}

(25px was randomly chosen, fill in the width of your background image..)

独夜无伴 2024-10-23 17:28:23

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...

那小子欠揍 2024-10-23 17:28:23

HTMLCSS

<div id="example-link">
  <a href="#">Link to journal article</a>
</div>

#example-link a { 

  background: url('images/shooting-stars/shooting-star-link.png'); 
}

HTML

<div id="example-link">
  <a href="#">Link to journal article</a>
</div>

CSS

#example-link a { 

  background: url('images/shooting-stars/shooting-star-link.png'); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文