2013-04-29 84 views
1

我正在嘗試顯示有序列表中列出的樂譜的預覽。我只能在懸停在< li>元素上時顯示圖像,但我希望僅在每行的第一部分懸停時顯示圖像(「[view]」)。我試過修改不同的東西,但是我不能正確地做。這是我的實驗迄今爲止:http://www.antonioromo.com/newsite/music.html懸停文本div時彈出圖片

我確定我有冗餘代碼,我可能只需要改變一些簡單的東西,但我不是專家。

這是我列出的項目的方式:

<div id="SheetMusicStore"> 
    <ol class="enlarge"> 
    <li> 
     <span class="view">[ view ]</span> 
     <span class="preview"><img src="images/01gnw-tn.png" alt="Just Another Dusk" /><br />Just Another Dusk (Good Night Wishes)</span> 
     <span class="name">Just Another Dusk (Good Night Wishes)</span> 
     <span class="price">$3.99 BUY</span> 
    </li> 
    <li> 
     <span class="view">[ view ]</span> 
     <span class="preview"><img src="images/02gnw-tn.png" alt="My Nightlight" /><br />My Nightlight (Good Night Wishes)</span> 
     <span class="name">My Nightlight (Good Night Wishes)</span> 
     <span class="price">$3.99 BUY</span> 
    </li> 
    </ol> 
</div> 

這是我的CSS代碼:

/** Sheet Music Store **/ 
#SheetMusicStore { 
    width: 500px; 
    margin: 40px auto; 
} 
ol.enlarge{ 
    margin-left:0; 
    font-family: 'Trebuchet MS', Helvetica, Tahoma, Arial, Sans-serif; 
    font-size: 1em; 
    color: #999; 
    padding: 10px 20px; 
    -moz-box-shadow: inset 0 2px 2px #582E58; 
    -webkit-box-shadow: inset 0 2px 2px #582E58; 
    box-shadow: inset 0 2px 2px #582E58; 
    border-radius: 6px; 
    -moz-border-radius: 6px; 
    -webkit-border-radius: 6px; 
    background: url(../images/sheet-bg.png) repeat 0 0 scroll; 
    color: #AAA; 
} 
ol.enlarge li{ 
    position: relative; 
    z-index: 0; /*resets the stack order of the list items - later we'll increase this*/ 
    text-shadow: 0 1px 1px rgba(0, 0, 0, .6); 
    background: transparent url(../images/sheet-item-bg.png) repeat-x bottom left scroll; 
    padding: 5px 0 7px 0; 
    list-style-position: inside; 
    font-size: 12px; 
} 
ol.enlarge img{ 
    background-color: #eae9d4; 
    padding: 6px; 
    -webkit-box-shadow: 0 0 6px rgba(132, 132, 132, .75); 
    -moz-box-shadow: 0 0 6px rgba(132, 132, 132, .75); 
    box-shadow: 0 0 6px rgba(132, 132, 132, .75); 
    -webkit-border-radius: 4px; 
    -moz-border-radius: 4px; 
    border-radius: 4px; 
} 
ol.enlarge span.preview{ 
    position: absolute; 
    left: -9999px; 
    background-color: #eae9d4; 
    padding: 10px; 
    font-family: 'Trebuchet MS', Helvetica, 'Droid Sans', sans-serif; 
    font-size: .9em; 
    text-align: center; 
    color: #495a62; 
    -webkit-box-shadow: 0 0 20px rgba(0,0,0, .75)); 
    -moz-box-shadow: 0 0 20px rgba(0,0,0, .75); 
    box-shadow: 0 0 20px rgba(0,0,0, .75); 
    -webkit-border-radius: 8px; 
    -moz-border-radius: 8px; 
    border-radius: 8px; 
} 
ol.enlarge li:hover{ 
    color: #EEE; 
    z-index: 50; 
} 
ol.enlarge li:hover .view{ 
    color:#FFFFCC !important; 
} 
ol.enlarge .view:hover{ 
    cursor: pointer; 
} 
ol.enlarge span.preview img{ 
    padding: 2px; 
    background: #ccc; 
} 
ol.enlarge li:hover span.preview{ 
    top: -300px; /*the distance from the bottom of the thumbnail to the top of the popup image*/ 
    left: 300px; /*distance from the left of the thumbnail to the left of the popup image*/ 
    z-index: 50; 
} 
ol.enlarge .price { 
    width: 62px; 
    height: 16px; 
    position: absolute; 
    top: 7px; 
    right: 0; 
    border-radius: 8px; 
    -moz-border-radius: 8px; 
    -webkit-border-radius: 8px; 
    background: transparent url(../images/buy-bg.png) repeat 0 0 scroll; 
    margin: 0 0 0 10px; 
    font-size: 10px; 
    text-align: center; 
    line-height: 16px; 
    text-shadow: none; 
    color: #BBB; 
    text-decoration: none; 
    z-index: 0; 
} 
ol.enlarge .price:hover { 
    color: #EEE; 
} 

而且,我不知道爲什麼會出現在留下了大量空白頁面的最底部。它是由動態創建的元素創建的嗎?預先感謝任何幫助!

+0

一般來說,改變'李:hover'到'span.view:hover'和'李:懸停跨度.preview「到'span.view:hover〜span.preview'。如果你可以提供一個[小提琴](http://jsfiddle.net),這樣會更容易,所以人們可以改變你的代碼並向你展示它。 – Passerby 2013-04-29 04:16:16

+0

非常感謝你的小提示。我甚至不知道存在!大約5年前我停止開發網站,現在它是一個不同的世界! :)我嘗試了你的建議,與Martin的下面一樣,但它仍然無效。我不知道我做錯了什麼。 :/ – 2013-04-30 05:07:20

+0

那麼我的建議與馬丁的建議不完全一樣,但邏輯是相似的。我檢查了你的鏈接,但問題仍然是我無法改變你的風格來測試。我仍然建議你做一個小提琴_yourself_。這不僅會爲人們提供便利,而且還有可能在你自己動手時,最終/意外地發現問題所在。 – Passerby 2013-04-30 05:22:29

回答

4

您可以將preview嵌套在view元素內。而只是改變了

ol.enlarge li:hover span.preview 

喜歡的東西

span.view:hover span.preview 

這裏是一個demo on jsfiddle

+0

非常感謝你的解決方案,Martin。我在jsfiddle檢查了它,我發現它工作正常,但由於某種原因,我無法在本地或在我的臨時站點上使用它。我甚至嘗試複製和粘貼,但仍然無法使用。我將您的解決方案留在了相同的鏈接中(http://www.antonioromo.com/newsite/music.html),以向您展示它的外觀。和昨天一樣,但現在圖像不顯示。我知道他們在那裏,因爲我改變的只是代碼。再次感謝您的幫助和耐心。 – 2013-04-30 05:11:02

+0

你必須確保在'view'中包含'preview'元素......如果這不夠清楚......它需要是:' [view] 圖像和標題'或在CSS中使用此選擇器:'span.view:hover〜span.preview' – 2013-04-30 08:11:22

+0

工作正常!非常感謝你,馬丁! :) – 2013-04-30 13:28:10