【问题标题】:Image background over the lines线条上的图像背景
【发布时间】:2011-09-28 03:03:52
【问题描述】:

我想获得带有图像的按钮链接。

I did,实际上,使用 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>

但是没有比使用负边距that don't work in IE7 更好的解决方案吗?我尝试将某个margin-top 放入section a 标签中,但由于页边距折叠,它不起作用。

(哇,我的名声不允许我嵌入图像或添加超过 2 个外部链接。)

【问题讨论】:

标签: css image html margin


【解决方案1】:

@吉尔;在您的代码中,您将图像放在链接之外,因此当您将图像悬停时,您的链接就会隐藏。我不知道你是有意还是无意。也许你可以使用绝对位置。

HTML

<a href="#"><span>&nbsp;</span>Sheet music (PDF)</a>

CSS

a{
    display:block;
    position:relative;
    text-decoration:none;
    -moz-border-radius: 10px 10px 10px 10px;    
    background: none repeat scroll 0 0 #0033CC;
    color: white;
    padding: 10px 10px 10px 60px;
    text-decoration: none;
    width: 150px;

}
a span{
    display:block;
    position:absolute;
    background: url("http://www.jill-jenn.net/drafts/background-image-over-the-lines/pdf.png") no-repeat ;
    width:50px;
    height:50px;
    top:-5px;
    left:10px;
}
a:hover{
    background:red;
}

检查这个例子 http://jsfiddle.net/sandeep/AwkwF/ 可能对你有帮助

【讨论】:

    【解决方案2】:

    或尝试类似的方法,几乎​​所有内容都相同,但图像背景位于 span 标签上

    <a href="#"><span>Sheet music (PDF)</span></a>
    

    【讨论】:

      猜你喜欢
      • 2019-02-27
      • 1970-01-01
      • 2012-05-24
      • 1970-01-01
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      • 1970-01-01
      相关资源
      最近更新 更多