1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Why only last image is displayed?

Discussion in 'C#' started by akinak, Jun 9, 2008.

  1. #1
    Iam building an image gallery. I want the page to display the thumbnails from the folder and then using CSS hover property, the bigger image be displayed. My thumbnails are named as image_th.jpg and the originals as image_bg.jpg. I have already done the coding, but when I hover over an image it displays only the last image from my folder(for each image). I don't understand why?

    Here is the asp code:
    <div id="content"><% 
    dim objFSO,objFolder,objFile
    Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
    Set objFolder=objFSO.GetFolder(Server.MapPath("hall"))
    for Each objFile in objFolder.Files
     if LCase(right(objFile.Name,6)="th.jpg") then 
         Response.Write "<img src='hall/"& objFile.Name &"'>"
       else %>
        <span><% Response.Write "<img src='hall/"& objFile.Name &"'>" %></span>
       <% end if	
    	Next
    Set objFolder=nothing
    Set objFSO=nothing %>
    </div>
    Code (markup):
    and CSS:

    #content span{
    	background-color:#FFFF00;
    	padding:0.5em;
    	height:200px;
    	width:200px;
    	border:medium; 
    	border-color:#FF0000;
    	border-style:solid;
    	position:absolute;
    	left:20em;
    	top:20em;
    	visibility:hidden;
    			 }
    	#content img{height:100px;
    		width:100px;
    		border:thin; 
    		border-color:#FF0000;
    		 border-style:solid;}
    	#content:hover span{
    		 visibility:visible;
    		 }
    Code (markup):
     
    akinak, Jun 9, 2008 IP
  2. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #2
    why you have set the span visibility to hidden?
    visibility:hidden;
     
    yugolancer, Jun 10, 2008 IP
  3. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    because I want the original image to be displayed only when someone hovers over the thumbnail..not otherwise
     
    akinak, Jun 10, 2008 IP
  4. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Mods,

    Can you please move this thread to CSS forum. I figured out that this is no more of an ASP problem. Its a CSS problem

    Thanks
     
    akinak, Jun 11, 2008 IP
  5. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #5
    Means, if i understand well you have bug in your style. Actually hover effect is reserved only for the links.
    Moreover a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective!!
    You cannot combine hover with CSS ID. That's why you see only the last image. Fix that and you'll see the rest of the images too.

    Regards :)
     
    yugolancer, Jun 11, 2008 IP
  6. yugolancer

    yugolancer Well-Known Member

    Messages:
    320
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    110
    #6
    Well, actually Pseudo-classes can be combined with CSS classes but not in a way you have done that.
     
    yugolancer, Jun 11, 2008 IP
  7. bclassic

    bclassic Peon

    Messages:
    205
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    yes, this is a css question
    yugolancer answered already

    yugolancer shall have a good rep
     
    bclassic, Jun 11, 2008 IP
  8. akinak

    akinak Peon

    Messages:
    256
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thnx for replying. but I am still not getting it. From your post I get that I am supposed to use <a> tag to use hover.
    So, I modified the code as below. But now, it displays all the images(I have visibilty:hidden before hover over an image).And thre is no hover.

    Here is the asp:
    <div id="content">
    
    <% 
    dim objFSO,objFolder,objFile
    Set objFSO=Server.CreateObject("Scripting.FileSystemObject")
    Set objFolder=objFSO.GetFolder(Server.MapPath("hall"))
    for Each objFile in objFolder.Files
     if LCase(right(objFile.Name,6)="th.jpg") then %>
     <a href="#resize" class="image">
        <% Response.Write "<img src='hall/"& objFile.Name &"'>" %> </a>
        <% else %>
        <span><a name="resize"><% Response.Write "<img src='hall/"& objFile.Name &"'>" %></a></span>
       <% end if	
    	Next
    Set objFolder=nothing
    Set objFSO=nothing %>
    
    	</div>
    Code (markup):
    and CSS:
    .image img{height:100px;
    		width:100px;
    		border:thin; 
    		border-color:#FF0000;
    		 border-style:solid;}
    
    	.image span {
    	background-color:#FFFF00;
    	padding:0.5em;
    	height:200px;
    	width:200px;
    	border:medium; 
    	border-color:#FF0000;
    	border-style:solid;
    	position:absolute;
    	left:30em;
    	top:30em;
    	visibility:hidden;	
    					 }
    		
    		.image:hover span{
    		 visibility:visible;
    		 		 		 }
    Code (markup):
     
    akinak, Jun 12, 2008 IP