html – 下拉菜单切断或出现在div后面

前端之家收集整理的这篇文章主要介绍了html – 下拉菜单切断或出现在div后面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个下拉菜单,出现在我的图像转换画廊div后面.下面是它的外观和 HTML和CSS的形象.

HTML:

  1. <body>
  2. <div id="top_bar">
  3. <div id="top_inner">
  4. <div id="logo"> <a href="http://www.edosbornephotography.com"><img src="images/logo.gif" alt="Ed Osborne" width="225" height="115" class="logo"></a></div>
  5. <div class="nav">
  6. <ul class = "menu" >
  7. <li> <a href = "#" > Home </a> </li>
  8. <li><a href = "#" > Packages </a>
  9. <li><a href = "#" > Weddings </a>
  10. <li><a href = "#" id="left" > Lifestyle </a>
  11. <ul class = "submenu" >
  12. <li> <a href = "#" > Families </a> </li>
  13. <li> <a href = "#"> Newborn/Child </a> </li>
  14. <li> <a href = "#" > Portraits </a> </li>
  15. </ul>
  16. </li>
  17.  
  18. <li> <a href = "#" > Blog </a> </li>
  19. <li><a href = "#" id="left"> Abous Us </a>
  20. <ul class = "submenu" >
  21. <li> <a href = "#" > Ed Osborne </a> </li>
  22. <li> <a href = "#" > Testimonials </a> </li>
  23. <li> <a href = "#" > FAQs </a> </li>
  24. </ul>
  25. </li>
  26.  
  27. <li> <a href = "#" > Contact Us </a> </li>
  28. <li> <a href = "#" > Links </a> </li>
  29. </ul>
  30. </div>
  31. </div>
  32. </div>
  33.  
  34. <div id="main">
  35.  
  36. <div id="smart-gallery">
  37. <a href="images/cubagallery-img-1.jpg">
  38. <img src="images/cubagallery-img-1.jpg" /></a>
  39.  
  40. <a href="images/cubagallery-img-15.jpg">
  41. <img src="images/cubagallery-img-15.jpg" /></a>
  42.  
  43. <a href="images/cubagallery-img-3.jpg">
  44. <img src="images/cubagallery-img-3.jpg" /></a>
  45.  
  46. <a href="images/cubagallery-img-4.jpg"></a>
  47. <img src="images/cubagallery-img-4.jpg" /></a>
  48. </div>
  49.  
  50. </div>

CSS:

  1. .min-gallery
  2. {
  3. width: 927px;
  4. height: 615px;
  5. border: solid 1px black;
  6. background-color: Black;
  7. background: url(../images/bg.jpg);
  8. margin: auto;
  9. margin-left: 232px;
  10. }
  11.  
  12. .min-gallery .preview
  13. {
  14. width: 852px;
  15. height: 493px;
  16. margin-top: 36px;
  17. margin-left: 36px;
  18. margin-right: 36px;
  19. position: relative;
  20. border: solid 2px black;
  21. overflow: hidden;
  22. background-color: White;
  23. }
  24.  
  25. .min-gallery .preview img
  26. {
  27. /* width: 795px; height: 525px;*/
  28. position: absolute;
  29. }
  30.  
  31. .min-gallery .bottom
  32. {
  33. width: 100%;
  34. height: 98px;
  35. color: Gray;
  36. font-family: Arial;
  37. font-size: 1em;
  38. font-weight: bold;
  39. overflow: hidden;
  40. }
  41.  
  42. #top_bar {
  43. width: 100%;
  44. height: 145px;
  45. background: #000000;
  46. padding-bottom: 20px;
  47. }
  48.  
  49. #top_inner {
  50. text-align: center;
  51. margin: 0 auto;
  52. width: 1000px;
  53. height: 144px;
  54. }
  55.  
  56. .nav {
  57. margin: 0 auto;
  58. position: relative;
  59. padding-top: 100px;
  60. }
  61.  
  62. ul.menu {
  63. list-style: none;
  64. margin: 0;
  65. float: left;
  66. background: #222;
  67. font-size: 1.2em;
  68. background: url(../images/topnav_bg.gif) repeat-x;
  69. }
  70. ul.menu li {
  71. float: left;
  72. margin: 0;
  73. position: relative;
  74. }
  75. ul.menu li a{
  76. padding: 10px 18px;
  77. color: #fff;
  78. display: block;
  79. text-decoration: none;
  80. float: left;
  81. }
  82.  
  83. ul.menu li a#left{
  84. padding: 10px 5px;
  85. color: #fff;
  86. display: block;
  87. text-decoration: none;
  88. float: left;
  89. }
  90.  
  91. ul.menu li a:hover {
  92. background: url(../images/topnav_hover.gif) no-repeat center top;
  93. }
  94.  
  95. ul.menu li span {
  96. width: 11px;
  97. height: 35px;
  98. float: left;
  99. background: url(../images/subnav_btn.gif) no-repeat center top;
  100. }
  101.  
  102. ul.menu li span.subhover {
  103. background-position: center bottom; cursor: pointer;
  104. }
  105.  
  106. ul.menu li ul.submenu {
  107. list-style: none;
  108. position: absolute;
  109. left: 0; top: 35px;
  110. background: #333;
  111. margin: 0; padding: 0;
  112. display: none;
  113. float: left;
  114. width: 170px;
  115. -moz-border-radius-bottomleft: 5px;
  116. -moz-border-radius-bottomright: 5px;
  117. -webkit-border-bottom-left-radius: 5px;
  118. -webkit-border-bottom-right-radius: 5px;
  119. border: 1px solid #111;
  120. }
  121.  
  122. ul.menu li ul.submenu li{
  123. margin: 0; padding: 0;
  124. border-top: 1px solid #252525;
  125. border-bottom: 1px solid #444;
  126. clear: both;
  127. width: 170px;
  128. }
  129.  
  130. html ul.menu li ul.submenu li a {
  131. float: left;
  132. width: 122px;
  133. padding-left: 30px;
  134. text-align: left;
  135. }

当我从.min-gallery .preview img中删除位置:absolute时,下拉菜单出现在上面,这是我想要的,但是图像停止改变,只是粘在一个图像上.

任何人快速修复?很抱歉,所有代码的粘贴,但我不知道我怎么能表达我的观点你们

谢谢

解决方法

设置下拉菜单的较高的z-index.
  1. .submenu { z-index: 999; }

原因“具有更大堆栈顺序的元素总是在具有较低堆栈顺序的元素的前面.

猜你在找的HTML相关文章