图像背景超过线条
我想获得带有图像的按钮链接。
我做到了,实际上,使用 CSS:
section a:link, section a:visited {
width: 150px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
-khtml-border-radius: 10px;
color: white;
background: #03c;
padding: 10px 10px 10px 60px;
display: block;
text-decoration: none;
}
section div {
margin-left: 5px;
margin-top: -9px;
width: 50px;
height: 50px;
float: left;
}
.pdf div {
background: transparent url('pdf.png') no-repeat 0 50%;
}
然后是 HTML:
<section class="pdf">
<div></div>
<a href="#">Sheet music (PDF)</a>
</section>
但是没有比使用负边距更好的解决方案吗? IE7?我尝试将某个 margin-top
放入 section a
标记中,但由于边距折叠,它不起作用。
(哇,我的声誉不允许我嵌入图像或添加超过 2 个外部链接。)
I would like to obtain button links with an image over the lines.
I did, actually, using CSS:
section a:link, section a:visited {
width: 150px;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
-khtml-border-radius: 10px;
color: white;
background: #03c;
padding: 10px 10px 10px 60px;
display: block;
text-decoration: none;
}
section div {
margin-left: 5px;
margin-top: -9px;
width: 50px;
height: 50px;
float: left;
}
.pdf div {
background: transparent url('pdf.png') no-repeat 0 50%;
}
Then HTML:
<section class="pdf">
<div></div>
<a href="#">Sheet music (PDF)</a>
</section>
But isn't there a better solution than using negative margins that don't work in IE7? I tried to put a certain margin-top
into section a
tags, but due to collapsing margins, it didn't work.
(Wow, my reputation didn't allow me to embed an image nor add more than 2 external links.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@吉尔;在您的代码中,您将图像放在链接外部,因此当您将鼠标悬停在图像上时,链接会隐藏。我不知道你是有意还是无意。也许你可以使用绝对位置。
HTML
CSS
检查此示例
http://jsfiddle.net/sandeep/AwkwF/
可能对你有帮助
@jill; in your code you put an image outside the link so when you hover the image then your link hide. i don't know you do it intentionally or not . may be you can use position absolute.
HTML
CSS
check this example
http://jsfiddle.net/sandeep/AwkwF/
may be that's help you
或者尝试这样的方法,几乎所有内容都是相同的,但图像背景位于 span 标签上
or try something like this, where almost everything is same, but image background is on span tag