944,050 Members | Top Members by Rank

Ad:
Apr 28th, 2006
0

Hover Image Position ???

Expand Post »
My website, which can be viewed on:

http://homepage.ntlworld.com/darsh25/alcohol.html

On the left menu, I want images appearing ONLY when we hover mouse over particular link (Beer/Wine/Whisky, etc.) & its submenus, which works perfectly well.

But what I want is ALL images appearing (only when mouse is hovered over a particular link) exactly at the same position/place, but right now, it seems popping below each other.

I want images appearing exactly as in:

http://www.meyerweb.com/eric/css/edge/popups/demo2.html

Can anyone please help ???

Following is the code for this particular thing:

/* ......... Left Menu Link Rollover Showing Image ............ */

#leftMenu ul li img
{
position:absolute;
top:340px;
left:20px;
height:100px;
width:100px;
}

#leftMenu ul li img {display:none;}
#leftMenu ul li:hover img {display:block;}


The Entire Style Sheet is:

HTML and CSS Syntax (Toggle Plain Text)
  1. /* CSS Document */
  2.  
  3. body
  4. {
  5. background-image:url(background_champagne.gif);
  6. background-attachment:fixed;
  7. }
  8.  
  9. /* ........................................ Banner ........................................ */
  10.  
  11. div.banner
  12. {
  13. width:40px;
  14. height:100px;
  15. }
  16.  
  17.  
  18. div.banner img
  19. {
  20. width:40px;
  21. height:50px;
  22. }
  23.  
  24. /* ......................................... Top Menu .................................... */
  25.  
  26. #topMenu
  27. {
  28. background-color:transparent;
  29. cursor:default;
  30. text-align:center;
  31. width:980px;
  32. float:right;
  33. }
  34.  
  35. #topMenu ul
  36. {
  37. list-style: none;
  38. font-size:medium;
  39. float:right;
  40. position:relative;
  41. margin-left: 130px;
  42. width:850px;
  43. padding: 0;
  44. }
  45.  
  46. #topMenu ul li
  47. {
  48. display: inline;
  49. border:1px solid black;
  50. width:210px;
  51. background-color:white;
  52. color:#FF00FF;
  53. float:left;
  54. position: relative;
  55. font-size:large;
  56. }
  57.  
  58. #topMenu ul li:hover
  59. {
  60. background-color:black;
  61. }
  62.  
  63. #topMenu a
  64. {
  65. display:block;
  66. text-decoration:none;
  67. font-size:large;
  68. color:blue;
  69. }
  70.  
  71. #topMenu a:hover
  72. {
  73. color:white;
  74. text-transform:uppercase;
  75. }
  76.  
  77. body {behavior: url(csshover.htc);}
  78.  
  79.  
  80. /* ....................................... Left Menu .......................................... */
  81.  
  82. #leftMenu
  83. {
  84. background-color:transparent;
  85. cursor:default;
  86. text-align:center;
  87. width:100px;
  88. float:left;
  89. }
  90.  
  91. #leftMenu ul
  92. {
  93. text-align:center;
  94. list-style:none;
  95. margin:0px;
  96. position:relative;
  97. padding:0px;
  98. width:120px;
  99. border:thin solid red;
  100. }
  101.  
  102. #leftMenu ul li
  103. {
  104. display: block;
  105. background-color:white;
  106. width:120px;
  107. border-bottom:thin solid red;
  108. color:blue;
  109. position: relative;
  110. font-size:large;
  111. line-height:50px;
  112. }
  113.  
  114. #leftMenu ul li:hover
  115. {
  116. color:black;
  117. background-color:yellow;
  118. text-transform:uppercase;
  119. }
  120.  
  121. #leftMenu ul li ul
  122. {
  123. position:absolute;
  124. display: none;
  125. text-transform:none;
  126. left:121px;
  127. width:123px;
  128. top:0px;
  129. }
  130.  
  131. #leftMenu a
  132. {
  133. display:block;
  134. position:relative;
  135. text-decoration:none;
  136. background-color:white;
  137. line-height:20px;
  138. font-size:large;
  139. width:123px;
  140. color:green;
  141. text-transform:none;
  142. }
  143.  
  144. #leftMenu a:hover
  145. {
  146. color:#00FFFF;
  147. background-color:black;
  148. }
  149.  
  150. #leftMenu ul li ul {display:none;}
  151. #leftMenu ul li:hover ul {display:block;}
  152.  
  153.  
  154. /* This Code is for Microsoft Internet Explorer Browser
  155. to it shows the effect of "li:hover" */
  156.  
  157. body { behavior: url(csshover.htc); }
  158.  
  159.  
  160. /* ........................... Left Menu Link Rollover Showing Image ....................... */
  161.  
  162. #leftMenu ul li img
  163. {
  164. position:absolute;
  165. top:340px;
  166. left:20px;
  167. height:100px;
  168. width:100px;
  169. }
  170.  
  171. #leftMenu ul li img {display:none;}
  172. #leftMenu ul li:hover img {display:block;}
  173.  
  174.  
  175. /* ................................... Content ................................................ */
  176.  
  177. #content
  178. {
  179. background-color:white;
  180. width:850px;
  181. border:1px solid green;
  182. float:right;
  183. }
  184.  
  185. #content h2
  186. {
  187. font-family:"Times New Roman", Times, serif;
  188. text-align:justify;
  189. margin:1em;
  190. color:#990033;
  191. text-decoration:underline;
  192. }
  193.  
  194. #content h3
  195. {
  196. font-family:Georgia, "Times New Roman", Times, serif;
  197. text-align:left;
  198. font-size:large;
  199. margin-left:20px;
  200. color:blue;
  201. text-decoration:none;
  202. }
  203.  
  204. #content h4
  205. {
  206. font-family:"Courier New", Courier, monospace;
  207. text-align:left;
  208. font-size:large;
  209. color:red;
  210. margin-left:20px;
  211. text-decoration:none;
  212. }
  213.  
  214. #content h5
  215. {
  216. font-family:"Courier New", Courier, monospace;
  217. text-align:left;
  218. font-size:large;
  219. color:fuchsia;
  220. margin-left:20px;
  221. text-decoration:none;
  222. }
  223.  
  224. #content h6
  225. {
  226. font-family:"Courier New", Courier, monospace;
  227. text-align:left;
  228. font-size:medium;
  229. color:black;
  230. margin-left:20px;
  231. text-decoration:underline;
  232. }
  233.  
  234. #content table
  235. {
  236. font-family:Verdana, Arial, Helvetica, sans-serif;
  237. text-align:left;
  238. font-size:medium;
  239. color:black;
  240. margin-left:20px;
  241. }
  242.  
  243. #content p
  244. {
  245. font-family:Verdana, Arial, Helvetica, sans-serif;
  246. text-align:justify;
  247. margin:1em 2em;
  248. color:black;
  249. }
  250.  
  251. #content p.first-letter:first-letter
  252. {
  253. color:red;
  254. margin-left:20px;
  255. font-size:xx-large;
  256. }
  257.  
  258. #content ul
  259. {
  260. font-family:Verdana, Arial, Helvetica, sans-serif;
  261. text-align:justify;
  262. color:black;
  263. margin:10px 50px;
  264. list-style-image:url(list_icon.gif);
  265. }
  266.  
  267. #content ul li
  268. {
  269. margin-top:15px;
  270. }
  271.  
  272. #content ol
  273. {
  274. font-family:Verdana, Arial, Helvetica, sans-serif;
  275. text-align:justify;
  276. color:black;
  277. margin:1em 1em 2em 3em;
  278. list-style-type:decimal;
  279. }
  280.  
  281. #content ol li
  282. {
  283. margin-top:20px;
  284. }
  285.  
  286. #content img.left
  287. {
  288. float:left;
  289. padding:10px;
  290. }
  291.  
  292. #content img.right
  293. {
  294. float:right;
  295. padding:10px;
  296. }
  297.  
  298. /* ................................... Bottom Menu ......................................... */
  299.  
  300.  
  301. #bottomMenu
  302. {
  303. border:1px solid red;
  304. float:left;
  305. background-color:black;
  306. color:#FFFFFF;
  307. text-align:center;
  308. font-family:"Times New Roman", Times, serif;
  309. font-style:italic;
  310. font-size:large;
  311. width:100%;
  312. height:5%;
  313. margin:0px;
  314. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
j4mes_bond25 is offline Offline
90 posts
since Jan 2006
Apr 28th, 2006
0

Re: Hover Image Position ???

The problem is related to absolute vs. relative positioning. "Absolute" doesn't really mean "absolute", it means, "relative to the nearest parent element which is absolutely-positioned, but disregarding that parent element's content". A mouthful, I know.

What's happening is... equally hard to explain. An experiment helps.

HTML and CSS Syntax (Toggle Plain Text)
  1. #leftMenu ul li img
  2. {
  3. position:absolute;
  4. top:340px;
  5. left:20px;
  6. height:100px;
  7. width:100px;
  8. }
Change the position to "relative". You can see that your image is PART OF the "li" element. It's position will be influenced by it. Technically, the li is relatively-positioned, so the img should still be absolute relative to the body, but this is a LIST, and so obeys its own box model (it's like its own private page, in a sense). Saying it another way, the LI element is seen as the parent of the image, acting as if the LI was absolutely positioned, even though it isn't. So, the image's "top" will always be relative to the LI's position. Said a third way: the natural order of the the elements of a list will always supercede and/or influence CSS positioning.

Your choices:

Take the images out of the MENU. Have a separate DIV, and use Javascript to position the proper image within that DIV.

-or-

Don't use a LIST for your menu. That will make your pop-outs much more difficult.

I attempt to explain CSS positioning in this article. When you read the part about Absolute Position, just keep in mind that your LI element will act as if it is absolute.
Last edited by tgreer; Apr 28th, 2006 at 1:09 pm.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Apr 28th, 2006
0

Re: Hover Image Position ???

Quote originally posted by tgreer ...

Your choices:

Take the images out of the MENU. Have a separate DIV, and use Javascript to position the proper image within that DIV.

-or-

Don't use a LIST for your menu. That will make your pop-outs much more difficult.

I attempt to explain CSS positioning in this article. When you read the part about Absolute Position, just keep in mind that your LI element will act as if it is absolute.
Thanks for your time & detailed explanation.

I'll delve into explanation bit further.

As far as you 2nd recommendation about NOT to use LIST. I wonder in that case, how could I possibly display these headings (Beer/Wine/Whisky, etc.) since right now, it's displayed as list & are "block".

As far as the pop-up i.e. sub menus is concerned, present, it's often a pain in the neck that it simply DOES NOT give viewer enough time to drag their mouse on the sub-menu's list (Introduction/Varieties/History, etc.), since by the time they drag their mouse pointer there, it just disappears.

Isn't there any way, I can have this sub-menu stay, at least long enough for viewers to be able to make a selection from this sub-menu's list ???
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
j4mes_bond25 is offline Offline
90 posts
since Jan 2006
Apr 28th, 2006
0

Re: Hover Image Position ???

You could leave the list as is. Place all of your images in their own absolutely-positioned DIV element. Just stack them on top of each other.

Use "onmouseover" and "onmouseout" to control either the CSS "visibility" or CSS "display" attribute of the appropiate image.

Your script should store the ID of the "current" image in a variable, so that the script can toggle it back off.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: google search form: directions?
Next Thread in HTML and CSS Forum Timeline: How do I get a objects property at runtime?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC