2015-01-15 112 views
0

我在做什么错?没有图片显示。 : - /(我切断了代码的底部,标签全部完成,我保证):悬停图片交换不起作用

在所有的教程中,我看着他们做了这件事,它展示了整个图片。但是当我这样做的时候它什么都没有显示。如果我在一个href标签里键入文本,它会显示文本背后的图片的一部分,但没有其他的东西。

CSS:

body { 
    background-color: #ebf4f7; 
    background-image: url(bg.png); 
    background-repeat: repeat-x; 
} 
#mainnav { 
    position: relative; 
    top: -9px; 
    left: -2px; 
    width: auto; 
    padding-right: 0%; 
    padding-left: 0%; 
} 
    .profilebutton { 
    background-image: url(button%20profile.png); 
    background-position: 0px 0px; 
    height: 71px; 
    width: 113px; 
} 
.profilebutton:hover { 
    background-image: url(button%20profile.png); 
    background-position: 0px 100%; 
    height: 71px; 
    width: 113px; 
} 

HTML:

<nav id="mainnav"> 
    <a href="my_profile.html" class="profilebutton"></a> 
+1

很肯定你需要显示:块;在你的个人资料按钮上 – atmd 2015-01-15 15:12:20

+0

背景图像什么时候不显示 - 只在悬停或所有时间? – Rhumborl 2015-01-15 15:13:12

+0

请摆脱您的文件名中的空格...耸耸肩 – cport1 2015-01-15 15:19:16

回答

1

<a>是一个内联元素,所以你必须给物业display: block;<a>元素,如果你不打算加入任何文字:Fiddle

.profilebutton { 
    display:block; 
    background-image: url('http://placekitten.com/300/303'); 
    background-position: 0px 100%; 
    height: 71px; 
    width: 113px; 
} 

body { 
 
    background-color: #ebf4f7; 
 
    background-image: url('http://placekitten.com/300/301'); 
 
    background-repeat: repeat-x; 
 
} 
 
#mainnav { 
 
    position: relative; 
 
    top: -9px; 
 
    left: -2px; 
 
    width: auto; 
 
    padding-right: 0%; 
 
    padding-left: 0%; 
 
} 
 
.profilebutton { 
 
    display:block; 
 
    background-image: url('http://placekitten.com/300/302'); 
 
    background-position: 0px 0px; 
 
    height: 71px; 
 
    width: 113px; 
 
} 
 
.profilebutton:hover { 
 
    display:block; 
 
    background-image: url('http://placekitten.com/300/303'); 
 
    background-position: 0px 100%; 
 
    height: 71px; 
 
    width: 113px; 
 
}
<nav id="mainnav"> 
 
<a href="my_profile.html" class="profilebutton">nbvnbvnchdfg</a>

+0

谢谢你做的伎俩! :) – 2015-01-15 16:13:46

+0

接受它作为答案,如果它。 – 2015-01-23 22:18:22