2013-09-26 99 views
1

我有代碼,當你翻轉圖像,它放大旁邊的它,但是當我添加另一個圖像,它放大在同一個地方,我如何使它,使每個圖像放大旁邊的小原來的一個?這是代碼;HTML懸停圖片代碼

<div id="imgmenu"> 
<div class="p1" title="Karla"><img src="small image" title="Thumbnail image" alt="Thumbnail image"/><img class="large" src="large image" title="enlarged view of image" alt="enlarged view of image" /></div></div> 
<style type="text/css"> 
<#imgmenu {position:relative; top:10px; left:10px; width:75px; background-color:#fff; z-index:100;} 
#imgmenu .p1 {display:block; width:150px; height:150px; text-decoration:none; background:#fff; top:0; left:0; border:0;} 
#imgmenu .p1:hover {text-decoration:none; background-color:#8c97a3; color:#000;} 
#imgmenu .large {display:block; position:absolute; width:0; height:0; border:0; top:0; left:0;} 
#imgmenu .p1:hover .large {display:block; position:absolute; top:-0px; left:150px; width:400px; height:300px; border:2px solid #ccc;} 
#info {z-index:100; height:22em;} 
</style> 


<div id="imgmenu"> 
<div class="p1" title="Beanie"><img src="small image" title="Thumbnail image" alt="Thumbnail image"/><img class="large" src="large image" title="enlarged view of image" alt="enlarged view of image" /></div></div> 
<style type="text/css"> 
<#imgmenu {position:relative; top:10px; left:10px; width:75px; background-color:#fff; z-index:100;} 
#imgmenu .p1 {display:block; width:150px; height:150px; text-decoration:none; background:#fff; top:0; left:0; border:0;} 
#imgmenu .p1:hover {text-decoration:none; background-color:#8c97a3; color:#000;} 
#imgmenu .large {display:block; position:absolute; width:0; height:0; border:0; top:0; left:0;} 
#imgmenu .p1:hover .large {display:block; position:absolute; top:-0px; left:150px; width:400px; height:300px; border:2px solid #ccc;} 
#info {z-index:100; height:22em;} 
    </style> 

回答

1

你的代碼有幾個錯誤。當你爲HTML中的元素定義一個id時,它必須是唯一的:在這裏,你使用兩個元素的<div id="imgmenu">。而是使用類。另外,不需要兩次定義CSS樣式。這裏有一個jsFiddle,我固定的一些東西,這裏的HTML:

<div class="imgmenu"> 
<div class="p1" title="Karla"> 
    <img src="http://placekitten.com/100/100" /> 
    <img class="large" src="http://placekitten.com/200/200" /> 
</div> 
</div> 

<div class="imgmenu"> 
<div class="p1" title="Beanie"> 
    <img src="http://placekitten.com/100/100" /> 
    <img class="large" src="http://placekitten.com/200/200" /> 
</div> 
</div> 

而這裏的CSS:

.imgmenu { 
    position:relative; 
    top:10px; 
    left:10px; 
    width:75px; 
    background-color:#fff; 
    z-index:100;} 

.imgmenu .p1 { 
    width:150px; 
    height:150px; 
    background:#fff;} 

.imgmenu .p1:hover { 
    background-color:#8c97a3; 
    color:#000;} 

.imgmenu .large { 
    position:absolute; width:0; height:0; border:0; top:0; left:0;} 

.imgmenu .p1:hover .large { 
    position:absolute; 
    left:150px; 
    width:400px; 
    height:300px; 
    border:2px solid #ccc;} 
+0

BTW,我更新,我刪除不亞於多餘的代碼作爲的jsfiddle可能的:http://jsfiddle.net/Lw8Kf/5/ – frenchie