Web Design Forum: Make a div visible when another is hoverd on - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Make a div visible when another is hoverd on

#1 User is offline   tangerine_dreamer 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 18
  • Joined: 18-February 11
  • Reputation: 0

Posted 18 January 2012 - 02:29 PM

Hi guys,

I am trying to get the #north_america_text div to show when the #north_america_image div is hovered over.


Here is some test code I am using
<div id="north_america">
      <div id="north_america_image">
      </div>
      <div id="north_america_text">
      </div>
</div> 


CSS
I've just used absolute positioning for testing, all will be floated etc later if I can get it to work.

#north_america	{
	height:150px;
	width:125px;
	border:1px solid #fff;
	position:absolute;
	top:150px;
	left:150px;
	position:relative;
}

#north_america_image	{
	height:80px;
	width:125px;
	position:absolute;
	top:0px;
	left:0px;
	border:1px solid #F00;
	
}
#north_america_text	{
	width:125px;
	height:30px;
	border:1px solid #0F0;
	visibility:hidden;
	position:absolute;
	bottom:0px;
	left:0px;
	
}

div#north_america_image:hover div#north_america_text {
	visibility:visible;
} 


This doesn't work, what does?!

Cheers

This post has been edited by Renaissance-Design: 18 January 2012 - 03:02 PM
Reason for edit: Please use the code button or tags to format your code.

0

#2 User is online   Renaissance-Design 

  • Available for custom WordPress work
  • View blog
  • Group: Moderators
  • Posts: 3,595
  • Joined: 12-August 10
  • Reputation: 559
  • Gender:Male
  • Location:South Wales
  • Experience:Web Guru
  • Area of Expertise:Designer/Coder

Posted 18 January 2012 - 03:04 PM

The reason it doesn't work is your selector targets a div called #north_america_text which is a descendant of #north_america_image, whereas in your markup they're siblings.
0

#3 User is offline   Wickham 

  • Web Guru
  • View gallery
  • Group: Moderators
  • Posts: 2,876
  • Joined: 11-June 09
  • Reputation: 257
  • Gender:Male
  • Location:Salisbury UK
  • Experience:Intermediate
  • Area of Expertise:Web Developer

Posted 18 January 2012 - 03:47 PM

Renaissance-Design is saying use your CSS with this markup:-
<div id="north_america">
      <div id="north_america_image">
      <!--</div> deleted-->
      <div id="north_america_text">
      </div>   
      </div><!--from above-->
</div> 


Add temporary background colors to every style to see what is happening.
#north_america	{   background: #ddd;
	height:150px;
	width:125px;
	border:1px solid #fff;
	position:absolute;
	top:150px;
	left:150px;
	position:relative;
}

#north_america_image	{  background: pink;
	height:80px;
	width:125px;
	position:absolute;
	top:0px;
	left:0px;
	border:1px solid #F00;
	
}
#north_america_text	{ background: yellow;
	width:125px;
	height:30px;
	border:1px solid #0F0;
	visibility:hidden;
	position:absolute;
	bottom:0px;
	left:0px;
	
}

div#north_america_image:hover div#north_america_text {
	visibility:visible;
} 


It looks a bit better if you edit #north_america height: 150px; to height: 80px so that it doesn't extend below the image div. Also if you want the text div to show just below the image div, edit #north_america_text delete bottom: 0; and add top: 80px; but I'm not quite sure what you want.

This post has been edited by Wickham: 18 January 2012 - 04:03 PM

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users