博客列表 >tab选项卡、移动端flex布局练习

tab选项卡、移动端flex布局练习

织网虾
织网虾原创
2021年11月12日 15:57:23492浏览

tab选项卡练习

运行效果图


html代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>tab选项卡</title>
  8. <link rel="stylesheet" href="css/index.css">
  9. <script src="js/index.js"></script>
  10. </head>
  11. <body>
  12. <div class="tab">
  13. <ul class="menu">
  14. <li class="current">健身</li>
  15. <li>编程</li>
  16. <li>音乐</li>
  17. <li>美食</li>
  18. <li>运维</li>
  19. </ul>
  20. <ul class="content c1">
  21. <li>减脂</li>
  22. <li>增肌</li>
  23. <li>蛋白</li>
  24. <li>HIIT</li>
  25. <li>有氧</li>
  26. </ul>
  27. <ul class="content hide">
  28. <li>php</li>
  29. <li>java</li>
  30. <li>python</li>
  31. <li>go</li>
  32. <li>c#</li>
  33. </ul>
  34. <ul class="content hide">
  35. <li>张信哲</li>
  36. <li>张学友</li>
  37. <li>she</li>
  38. <li>tfs</li>
  39. <li>光良</li>
  40. </ul>
  41. <ul class="content hide">
  42. <li></li>
  43. <li></li>
  44. <li></li>
  45. <li>面包</li>
  46. <li>饮料</li>
  47. </ul>
  48. <ul class="content hide">
  49. <li>linux</li>
  50. <li>windwos</li>
  51. <li>docker</li>
  52. <li>openstack</li>
  53. <li>k8s</li>
  54. </ul>
  55. </div>
  56. </body>
  57. </html>

css代码

  1. ul,li{
  2. list-style: none;
  3. margin:0;
  4. padding:0
  5. }
  6. .tab{
  7. width:302px;
  8. height: 200px;
  9. border: 1px solid #ccc;
  10. box-sizing: border-box;
  11. }
  12. .tab .menu{
  13. height: 30px;
  14. box-sizing: border-box;
  15. background-color: azure;
  16. }
  17. .tab .menu li{
  18. float:left;
  19. border-right:1px solid #ccc;
  20. border-bottom: 1px solid #ccc;
  21. width:60px;
  22. height: 30px;
  23. line-height:30px;
  24. text-align: center;
  25. box-sizing: border-box;
  26. font-size:14px;
  27. }
  28. .tab li:last-child{
  29. border-right: none;
  30. }
  31. .tab .menu .current{
  32. border-bottom: none;
  33. color:brown;
  34. font-weight: bold;
  35. background-color:#fff;
  36. }
  37. .tab .content{
  38. height:170px;
  39. }
  40. .tab .content li{
  41. font-size:12px;
  42. text-indent: 2em;
  43. height:25px;
  44. line-height:25px
  45. }
  46. .hide{
  47. display: none;
  48. }
  49. .tab .menu li:hover{
  50. border-bottom: none;
  51. color:brown;
  52. font-weight: bold;
  53. background-color:#fff;
  54. }
  55. .tab .menu li:hover .c2{
  56. display: block;
  57. }

js 代码

  1. window.onload=function(){
  2. let c1=document.querySelectorAll(".menu li");
  3. let content=document.querySelectorAll(".content");
  4. c1.forEach(function(el,index){
  5. el.onmouseover=function(){
  6. c1[0].classList.remove("current");
  7. content.forEach(function(el){
  8. el.style.display="none";
  9. })
  10. content[index].style.display="block";
  11. }
  12. });
  13. };

移动端flex布局,结合定位(菜单里的黑色圆圈)

效果图

html代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <link rel="stylesheet" href="css/ex.css">
  9. </head>
  10. <body>
  11. <div class="main">
  12. <div class="header">
  13. <h1>我的APP</h1>
  14. </div>
  15. <div class="content">
  16. <img src="img/22.jpg" />
  17. </div>
  18. <div class="foot">
  19. <ul class="icon"></ul>
  20. <div class="menu">新闻</div>
  21. <div class="menu">梦想</div>
  22. <div class="menu">收藏</div>
  23. </div>
  24. </div>
  25. </body>
  26. </html>

css 代码

  1. body{
  2. margin:0;
  3. padding:0;
  4. }
  5. .main{
  6. display:flex;
  7. flex-direction:column;
  8. width: 375px;
  9. height: 667px;
  10. }
  11. .header{
  12. background-color:crimson;
  13. flex: 1;
  14. flex-direction:column;
  15. vertical-align: middle;
  16. text-align:center
  17. }
  18. h1{
  19. font-size:14px;
  20. font-weight: bold;
  21. color:#fff;
  22. }
  23. .content{
  24. background-color: cadetblue;
  25. flex: 8
  26. }
  27. .content img{
  28. width: 100%;
  29. border: 0
  30. }
  31. .foot{
  32. background-color:darkgray;
  33. flex:1;
  34. display:flex;
  35. flex-direction:row;
  36. align-items:center
  37. }
  38. .foot .menu{
  39. flex: 1;
  40. text-align:center;
  41. position:relative;
  42. }
  43. .icon{
  44. background: url(../img/movie@highlight.png) no-repeat;
  45. background-size: 40%;
  46. width: 33%;
  47. height:50px;
  48. position: absolute;
  49. left:42%;
  50. }
声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议