2015-01-15 111 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