css實現響應下拉式菜單的代碼

來源:互聯網
上載者:User
這篇文章分享給大家的內容是關於css實現響應下拉式菜單的代碼,內容很有參考價值,希望可以幫到有需要的小夥伴。

一、簡介

響應式下拉式功能表可在多個移動端顯示會有不同的效果。

二、代碼如下

<!doctype html><html>    <head>        <meta charset="utf-8"/>        <meta name="viewport" content="width=device-width"/>        <title>響應式下拉式功能表</title>        <link rel="stylesheet" type="text/css" href="demo020.css" media="screen and (min-width:1024px)"/>        <link rel="stylesheet" type="text/css" href="demo021.css" media="screen and (max-width:1024px)"/>        <link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">    </head>    <body>        <p class="nav">            <p class="toggle">                <img class="tu" src="shitu2.png"/>                <i id="btn" class="fa fa-bars"></i>            </p>                <p class="bb"></p>            <ul id="menu" class="clearfix">                <li><a href="#">First</a></li>                <li><a href="#">Second</a></li>                <li><a href="#">Third</a></li>                <li><a href="#">Fourth</a></li>                <li><a href="#">Fifth</a></li>            </ul>        </p>        <script type="text/javascript">            var  btn=document.getElementById("btn");            var  menu=document.getElementById("menu");                        btn.onclick=function(){                //alert(1);                if(menu.style.display=="none"){                    menu.style.display="block";                }else{                    menu.style.display="none";                }            }                        window.onresize=function(){                var vw=document.documentElement.clienWidth;                if(vw>640){                    menu.style.display="block";                }            }        </script>    </body></html>

body{

margin:0;

}
.nav{

width:100%;background-color:#00316b;position:relative;

}
ul{

padding:0px;margin:0px;width:80%;margin:0 auto;background:#00316b;

}
ul>li{

list-style:none;float:left;

}
ul>li>a{

color:#fff;text-decoration:none;display:block;padding:20px 30px;

}
ul>li:hover{

background-color:red;

}
.clearfix:after{

display:block;content:"";height:0px;visibility:hidden;clear:both;

}
.clearfix{

zoom:1;

}
.toggle{

text-align:right;color:#fff;padding:20px;font-size:20px;background:black;/* background-color:#001r44; */display:none;overflow:hidden;

}
.tu{

float:left;

}
.bb{

position:absolute;background-image:url(shitu2.png);background-repeat:no-repeat;background-size:100px;width:100px;height:40px;left:20px;top:10px;

}

----------body{    margin:0;}.nav{    width:100%;    background-color:#00316b;}ul{    padding:0px;    margin:0px;    width:100%;    margin:0 auto;    background:#00316b;}ul>li{    text-align:center;    list-style:none;    /* float:left; */}ul>li>a{    color:#fff;    text-decoration:none;    display:block;    padding:20px 30px;}ul>li:hover{    background-color:red;}.clearfix:after{    display:block;    content:"";    height:0px;    visibility:hidden;    clear:both;}.clearfix{    zoom:1;}.toggle{    text-align:right;    color:#fff;    padding:20px;    background:yellow;    font-size:20px;    overflow:hidden;    display:block;}.tu{    float:left;    width:100px;}

第三、如下

這是視口大於1024px的時候所顯示的內容<PC端>
min-width:1024px

這是視口小於1024px的時候所顯示的內容<手機>
max-width:1024px
這是在手機上和iPad上的

相關推薦:

css和js如何?響應式導覽功能表

css如何自訂捲軸(代碼)

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.