Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
96
rated 0 times [  101] [ 5]  / answers: 1 / hits: 22596  / 13 Years ago, sun, december 4, 2011, 12:00:00

I am trying to create a popup in CSS. In this case, it's a small div containing text labeling the image you're hovering. However, I am definitely doing it wrong. I am either positioning the :hover div in CSS incorrectly (I've tried different positions (fixed, absolute, float, clear, etc.), but it keeps showing up inside the main div. I could wrong with my HTML, as I'm placing it within the main div that you hover for the popup to appear. But I'd think it has to be there to show up when you hover the main div. Any help is appreciated. Code below:



HTML:



<div class=topIcons topIconsHover topLabelHover>
<a href=image.html><img src=icons/image.png /></a>
<div class=topLabelHover>Image</div>
</div>


CSS:



.topIcons {
padding:14px 6px 10px 6px;
float:right;
}

.topIconsHover:hover {
background-color:#555555;
cursor:pointer
}

.topLabelHover:hover {
background-color:#555555;
width:80px;
height:24px;
position:fixed;
top:40px;
}


I am fine with using JavaScript (or JQuery) if it's necessary, but it seems like something simple enough for CSS. Also, is it better to use CSS over JavaScript (or Jquery) when possible because perhaps it's faster? I could be mistaken there, but would be interested to of the best practice.



edit* Still having trouble so thought I'd explain further what I'm trying to do with my page layout and perhaps it'll help. I have a series of icons in a navigation bar, all floated right. Upon hovering, I'd like the background to change (which I've managed in CSS with the topIconsHover class) and for a label div to appear beneath the related hovered icon div in the navigation bar when hovered.


More From » jquery

 Answers
21

Think you want something like this:



.topIcons {
padding:14px 6px 10px 6px;
float:right;
}

.topIconsHover:hover {
background-color:#555555;
cursor:pointer
}

.topLabelHover {
display:none;
}

.topIconsHover:hover .topLabelHover {
display:block;
position:absolute;
background-color:#555555;
width:80px;
height:24px;
top:40px;
}


http://jsfiddle.net/kHPZK/


[#88756] Friday, December 2, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaleyv

Total Points: 259
Total Questions: 99
Total Answers: 107

Location: Saint Helena
Member since Tue, Nov 3, 2020
4 Years ago
;