2013-04-29 86 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