zoukankan      html  css  js  c++  java
  • 一个用纯CSS实现的下拉菜单

    用CSS做下拉列表的特效,代码如下:

    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
            <title></title>
            <style type="text/css">
                * {
                    margin: 0px;
                    padding: 0px;
                }
                
                #nav {
                    width: 500px;
                    background-color: #737373;
                    height: 40px;
                    /*border-radius: 10px;*/
                    position: relative;
                    margin: 0px auto;
                    top: 0px;
                }
                
                .nav-container {
                    width: 100%;
                    height: 40px;
                    position: absolute;
                }
                
                .banner {
                    float: left;
                    text-align: center;
                    height: 40px;
                    width: 20%;
                    line-height: 40px;
                }
                
                .banner:hover {
                    background-color: #00BFFF;
                    cursor: pointer;
                }
                
                div ul {
                    list-style: none;
                    /*display: none;*/
                    background-color: blue;
                    overflow: hidden;
                    /*模拟height:auto时候的情况*/                
                    max-height: 0px;
                    transition: max-height 0.3s;
                    /*多浏览器支持*/
                    -moz-transition: height 1s;
                    -webkit-transition: height 1s;
                    -o-transition: height 1s;
                }
                
                .banner:hover ul {
                    /*display: block;*/
                    width: 100%;
                    max-height: 160px;
                }
                
                div ul li {
                    overflow: hidden;
                }
                
                div ul li:hover {
                    background-color: red;
                }
            </style>
        </head>
    
        <body>
            <div class="nav-container">
                <div id="nav">
                    <div id="nav-button-1" class="banner">第1个导航
                        <ul>
                            <li>1</li>
                            <li>2</li>
                            <li>3</li>
                            <li>4</li>
                        </ul>
                    </div>
                    <div id="nav-button-2" class="banner">第2个导航
                        <ul>
                            <li>1</li>
                            <li>2</li>
                            <li>3</li>
                        </ul>
                    </div>
                    <div id="nav-button-3" class="banner">第3个导航
                        <ul>
                            <li>1</li>
                            <li>2</li>
                        </ul>
                    </div>
                    <div id="nav-button-4" class="banner">第4个导航
                        <ul>
                            <li>1</li>
                            <li>2</li>
                            <li>3</li>
                            <li>4</li>
                            <li>5</li>
                        </ul>
                    </div>
                    <div id="nav-button-5" class="banner">第5个导航
                        <ul>
                            <li>1</li>
                            <li>2</li>
                            <li>3</li>
                            <li>4</li>
                            <li>5</li>
                        </ul>
                    </div>
                </div>
            </div>
    
        </body>
    
    </html>

    效果如下:

    这就是做出来的样子,当然可以做成横向列表,自己试着做一下。

  • 相关阅读:
    【leetcode】49. 字母异位词分组
    【leetcode】48. 旋转图像
    【leetcode】48. 全排列 2
    Day4前端学习之路——背景边框列表链接和更复杂的选择器
    Day3前端学习之路——CSS基本知识
    Day2前端学习之路——HTML基本知识
    Day1前端学习之路——概述
    Axure实现抽奖转盘(二)
    Axure实现百度登录页面(一)
    线性代数课程较好的资料
  • 原文地址:https://www.cnblogs.com/axj1993/p/6221729.html
Copyright © 2011-2022 走看看