当前位置:   article > 正文

div+css实例布局(一)_div css布局实例

div css布局实例

导航是前端开发中避免不了的一个区域,今天就来写写导航栏。

导航栏(一)

  1. <div id='menu'>
  2. <a href="#">链接</a>|
  3. <a href="#">链接</a>|
  4. <a href="#">链接</a>|
  5. <a href="#">链接</a>|
  6. <a href="#">链接</a>
  7. </div>
  1. *{margin:0;padding:0}
  2. #menu{
  3. min-width:400px;
  4. height:2rem;
  5. background:#06f;
  6. text-align:center;
  7. line-height:2rem;
  8. font-size:1rem;
  9. }
  10. #menu a{
  11. padding:0 1rem;
  12. color:#000;
  13. text-decoration:none;
  14. font-weight:bold
  15. }
  16. #menu a:hover{color:#FFC0CB}

导航栏(二)

  1. <ul id="menu">
  2. <li><a href="#">首页</a></li>
  3. <li><a href="#">首页</a></li>
  4. <li><a href="#">首页</a></li>
  5. <li><a href="#">首页</a></li>
  6. <li><a href="#">首页</a></li>
  7. <li><a href="#">首页</a></li>
  8. </ul>
  1. *{margin:0;padding:0}
  2. body{min-width:500px;}
  3. li{list-style:none}
  4. body{text-align:center}
  5. a{text-decoration:none}
  6. a:hover{color:#BA2636}
  7. #menu{ width:100%; height:3.75rem; background:#00A2CA;}
  8. #menu li{display:inline; height:3.75rem}
  9. #menu li a{display:inline-block; padding:0 1.25rem; height:3.75rem; line-height:3.75rem;
  10. color:#FFF;font-weight:bold;font-size:1rem}
  11. #menu li a:hover{background:#0095BB}

移动端底部滑动导航栏(三)

测试时候需要调成移动端

  1. <div id="nav">
  2. <footer id="footer">
  3. <div class="flex">
  4. <div class="top" ></div>
  5. <div class="bottom" >首页</div>
  6. </div><div class="flex">
  7. <div class="top" ></div>
  8. <div class="bottom" >首页</div>
  9. </div><div class="flex">
  10. <div class="top" ></div>
  11. <div class="bottom" >首页</div>
  12. </div><div class="flex">
  13. <div class="top" ></div>
  14. <div class="bottom" >首页</div>
  15. </div><div class="flex">
  16. <div class="top" ></div>
  17. <div class="bottom" >首页</div>
  18. </div><div class="flex">
  19. <div class="top" ></div>
  20. <div class="bottom" >首页</div>
  21. </div><div class="flex">
  22. <div class="top" ></div>
  23. <div class="bottom" >首页</div>
  24. </div>
  25. </footer>
  26. </div>
  1. *{ margin: 0;padding: 0;}
  2. #nav{
  3. width: 100%;
  4. height: 4rem;
  5. position: fixed;
  6. bottom: 0;
  7. margin: 0 0 0.625rem 0;
  8. }
  9. #footer
  10. {
  11. width: 100%;
  12. white-space: nowrap;
  13. overflow-x: auto;
  14. cursor: pointer;
  15. }
  16. /*将容器分为上下2部分*/
  17. #footer .flex
  18. {
  19. width: 5rem;
  20. height: 4rem;
  21. display: inline-block;
  22. border: 1px solid #808080;
  23. }
  24. .top{
  25. width: 100%;
  26. height: 3rem;
  27. background: url("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4075723771,1234971875&fm=27&gp=0.jpg") center center no-repeat;
  28. background-size: 100% 100%;
  29. }
  30. .bottom{
  31. width: 100%;
  32. height: 1rem;
  33. line-height: 1rem;
  34. text-align: center;
  35. }

响应式导航栏

  1. <header>
  2. <nav class="nav">
  3. <input type="checkbox" id="toggle" class="toggle"/>
  4. <label for="toggle">
  5. <span class="menu-icon">
  6. <svg viewBox="0 0 18 15" width="18px" height="15px">
  7. <path fill="white" d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.031C17.335,0,18,0.665,18,1.484L18,1.484z"/>
  8. <path fill="white" d="M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0c0-0.82,0.665-1.484,1.484-1.484 h15.031C17.335,6.031,18,6.696,18,7.516L18,7.516z"/>
  9. <path fill="white" d="M18,13.516C18,14.335,17.335,15,16.516,15H1.484C0.665,15,0,14.335,0,13.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.031C17.335,12.031,18,12.696,18,13.516L18,13.516z"/>
  10. </svg>
  11. </span>
  12. </label>
  13. <ul class="list">
  14. <li><a href="#">菜单一</a></li>
  15. <li><a href="#">菜单二</a></li>
  16. <li><a href="#">菜单三</a></li>
  17. <li><a href="#">菜单四</a></li>
  18. <li><a href="#">菜单五</a></li>
  19. </div>
  20. </nav>
  21. </header>
  1. *{margin:0;padding:0}
  2. .nav{background:#abc;height:3rem;display:block}
  3. .list{z-index:0;display:block;}
  4. li{list-style:none;float:left;margin-left:2rem;}
  5. a{text-decoration:none;color:#fff;line-height:3rem;}
  6. a:hover{color:#FFC0CB}
  7. input:checked~.list{
  8. position:absolute;
  9. padding:0 0.3rem 0.3rem 0.3rem;
  10. display:block;
  11. background: #abc;
  12. z-index:0;
  13. margin-top:3rem;
  14. }
  15. input:checked~.list li{clear:both;background: #abc;}
  16. label{display:none}
  17. .toggle{display:none}
  18. @media screen and (max-width:500px) {
  19. .toggle{display:none}
  20. label{display:block;z-index:4}
  21. .list{display:none;margin-left:0;}
  22. li{margin-left:0;}
  23. .meun-icon{display: block;float: left; }
  24. .menu-icon>svg path{fill: white; }
  25. label[for="toggle"] {
  26. display: block;
  27. float:left;
  28. z-index:2;
  29. cursor:ponter;
  30. line-height:3rem;
  31. margin-left:1rem
  32. }
  33. }

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/325510
推荐阅读
相关标签
  

闽ICP备14008679号