大图背景悬停导航菜单

栏目: Html · 发布时间: 4年前

核心属性

padding-top: 40% 为菜单项的背景预留空间

background-size: cover 背景图完全覆盖背景区域,但是可能会有部分看不到

:hover + transition + opacity + z-index 悬停显示子菜单的动画效果

@media + flex-direction: row 自适应小屏幕,使菜单项内容水平排列

本文使用了不写闭合标签的方法来去除inline-block元素之间的间隙。

  1. <div class="menu">
  2. <h1>欢迎来到旧金山</h1>
  3. <dl>
  4. <dt><a href=#>攻略</a>
  5. <dd>
  6. <a href=#>
  7. 景点,天气,路线等
  8. <img src=https://pics.codecolor.cn/responsive-panel-menu/view-from-st-regis.jpg alt>
  9. </a>
  10. <dt><a href=#>旅行</a>
  11. <dd class=tours>
  12. <a href=#>
  13. 如何周游:通过陆地、海洋和天空
  14. <img src=https://pics.codecolor.cn/responsive-panel-menu/market-streetcar.jpg alt>
  15. </a>
  16. <dt><a href=#>宾馆</a>
  17. <dd class=hotels>
  18. <a href=#>
  19. 住在哪里?价格要适合符合预算
  20. <img src=https://pics.codecolor.cn/responsive-panel-menu/st-regis-pool.jpg alt>
  21. </a>
  22. <dt><a href=#>事件</a>
  23. <dd class=events>
  24. <a href=#>
  25. 从购物市场到年度活动和各种音乐会
  26. <img src=https://pics.codecolor.cn/responsive-panel-menu/wrapped-boxes.jpg alt>
  27. </a>
  28. </dl>
  29. </div>
  1. * {
  2. box-sizing: border-box;
  3. }
  4. body {
  5. margin: 0;
  6. background: #101;
  7. }
  8. div a {
  9. color: #fff;
  10. text-decoration: none;
  11. }
  12. h1 {
  13. position: absolute;
  14. width: 100%;
  15. padding: 0 1rem;
  16. margin-top: 3rem;
  17. color: #fff;
  18. font-size: 3rem;
  19. line-height: 1;
  20. font-weight: 100;
  21. text-align: center;
  22. z-index: 1;
  23. transition: .3s;
  24. }
  25. dl {
  26. position: relative;
  27. margin-top: 0;
  28. padding-top: 40%;
  29. background-image: url(https://pics.codecolor.cn/responsive-panel-menu/golden-gate.jpg);
  30. background-size: cover;
  31. }
  32. dt {
  33. display: inline-block;
  34. width: 25%;
  35. padding: .5rem;
  36. text-align: center;
  37. background: rgba(0,0,0,0.5);
  38. }
  39. dt a {
  40. display: block;
  41. font-size: 1.2rem;
  42. }
  43. dd {
  44. position: absolute;
  45. top: 0;
  46. left: 0;
  47. width: 25%;
  48. height: 40vw;
  49. margin: 0;
  50. opacity: 0;
  51. background: rgba(255,0,0,0.4);
  52. transition: .65s opacity;
  53. }
  54. dd.tours {
  55. left: 25%;
  56. background: rgba(255,255,0,0.4);
  57. }
  58. dd.hotels {
  59. left: 50%;
  60. background: rgba(255,0,255,0.4);
  61. }
  62. dd.events {
  63. left: 75%;
  64. background: rgba(0,255,255,0.4);
  65. }
  66. dd a {
  67. display: flex;
  68. flex-direction: column;
  69. padding: 1.4rem;
  70. font-size: 1.2rem;
  71. opacity: 0;
  72. transition: .7s .3s;
  73. }
  74. dd a img {
  75. display: block;
  76. width: 100%;
  77. height: auto;
  78. margin-top: 1rem;
  79. margin-bottom: 5rem;
  80. }
  81. div:hover h1, div:focus h1 {
  82. opacity: 0;
  83. z-index: 0;
  84. }
  85. dt:hover + dd, dt:hover + dd a, dt:focus + dd, dt:focus + dd a {
  86. opacity: 1;
  87. }
  88. dd:hover, dd:focus, dd:hover a, dd:focus a {
  89. opacity: 1;
  90. }
  91. @media screen and (max-width: 700px) {
  92. dd {
  93. width: 100% !important;
  94. left: 0 !important;
  95. pointer-events: none;
  96. }
  97. dd a {
  98. flex-direction: row;
  99. justify-content: none;
  100. padding: 0;
  101. height: 100%;
  102. }
  103. dd a img {
  104. margin-top: 0;
  105. margin-left: 3rem;
  106. height: 100%;
  107. }
  108. }
  109. @media screen and (max-width: 500px) {
  110. h1 {
  111. font-size: 1.5rem;
  112. margin-top: 1.5rem;
  113. }
  114. }

以上所述就是小编给大家介绍的《大图背景悬停导航菜单》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

How to Build a Billion Dollar App

How to Build a Billion Dollar App

George Berkowski / Little, Brown Book Group / 2015-4-1 / USD 24.95

Apps have changed the way we communicate, shop, play, interact and travel and their phenomenal popularity has presented possibly the biggest business opportunity in history. In How to Build a Billi......一起来看看 《How to Build a Billion Dollar App》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

SHA 加密
SHA 加密

SHA 加密工具