博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CSS菜单实现
阅读量:5095 次
发布时间:2019-06-13

本文共 2185 字,大约阅读时间需要 7 分钟。

只含一层的菜单
    <nav class="list1">
        <ul>
            <li><a href="#">a</a></li>
            <li><a href="#">b</a></li>
            <li><a href="#">c</a></li>
            <li><a href="#">d</a></li>
            <li><a href="#">e</a></li>
        </ul>
    </nav>
一层纵向菜单
    li {list-style:none;}(默认圆点不美观)
    列表项之间设置border
    a {text-textdecoration:none;}(默认下划线不美观)
    a:hover也要重新设置
    a {display:block;}把a的区域扩充到父元素
一层横向菜单
    ul {overflow:hidden;}(内容一多溢出就不可见了)
    li {float:left;}
    a {display:block;}扩充点击区域至整个父元素
多层嵌套的菜单
    <nav class="multi_drop_menu">
            <ul>
                <li><a href="#">1</a></li>
                <li><a href="#">1</a></li>
                <li><a href="#">1</a></li>
                <li><a href="#">1</a>
                    <ul>
                        <li><a href="#">2</a></li>
                        <li><a href="#">2</a></li>
                        <li><a href="#">2</a>
                            <ul>
                                <li><a href="#">3</a></li>
                                <li><a href="#">3</a></li>
                                <li><a href="#">3</a></li>
                                <li><a href="#">3</a></li>
                            </ul>
                        </li>
                        <li><a href="#">2</a></li>
                    </ul>
                </li>
            </ul>
    </nav>
多层嵌套下拉菜单
            .multi_drop_menu * {
                margin:0;
                padding:0;
                }/*减少原来的内外边距对布局的影响*/
            .multi_drop_menu {
                font:1em helvetica, arial,/*微软的无衬线字体*/ sans-serif;/*无衬线字体*/
            }
            .multi_drop_menu a {
                display:block;/*链接区域扩充到整个容器*/
                color:#555;
                background-color:#eee;
                padding:.2em 1em;/*1em相当于body的font-size大小,默认情况下为16px,当然可以修改*/
                border-width:3px;
                border-color:transparent;
            }
            .multi_drop_menu a:hover {
                color:#fff;
                background-color:#aaa;
            }
            .multi_drop_menu a:active {
                color:#ccc;
                background:#fff;/*背景相关的都能写到background里面来*/
            }
            .multi_drop_menu ul {
                float:left;
            }
            .multi_drop_menu li {
                float:left;
                position:relative;/*给子元素的absolute定位提供定位上下文*/
                list-style:none;
            }
            .multi_drop_menu li:last-child a {
                border-right-style:none;
            }
            .multi_drop_menu li a {
                display:block;
                border-right-style:solid;
                background-clip:padding-box;/*选定背景显示的盒子区域*/
                text-decoration:none;
            }
            .multi_drop_menu li ul {
                width:9em;
                display:none;/*默认不显示,hover时显示*/
                position:absolute;
                left:0;
                top:100%;
            }
            .multi_drop_menu li:hover > ul {
                display:block;
            }/*>左边的只能是父元素*/
            .multi_drop_menu li li {
                float:none;
            }
            .multi_drop_menu li li a {
                border-right-style:none;
                border-top-style:solid;
            }
            .multi_drop_menu li li ul {
                display:none;
            }
            .multi_drop_menu li li ul {
                position:absolute;
                left:100%;
                top:0;
            }
            .multi_drop_menu.vertical li {
                float:none;
            }
            .multi_drop_menu.vertical li ul {
                left:100%;
                top:0;
            }

转载于:https://www.cnblogs.com/cyberpaz/p/4032739.html

你可能感兴趣的文章
ajax 设置Access-Control-Allow-Origin实现跨域访问
查看>>
截图方式预览文件
查看>>
opencv中的高维矩阵Mat
查看>>
vm ubuntu如何设置全屏
查看>>
selenium webdriver ChromeOptions
查看>>
课堂练习—数组最大值
查看>>
[HNOI2007]最小矩形覆盖
查看>>
人生难免有几次踩到大便的时候
查看>>
安卓开发利器 谷歌发布Android Studio工具
查看>>
超时设置
查看>>
工程代码目录结构及框架
查看>>
Ruby程序设计语言快速入门之变量与赋值
查看>>
比赛:小奔与不等四边形solution
查看>>
html块级元素和内联元素区别详解
查看>>
bzoj 1072状压DP
查看>>
用Java实现网络爬虫
查看>>
centos7部署DNS-1
查看>>
品牌和产品包装杂项
查看>>
三国反思录
查看>>
Win7 一键获得管理所有权限(最高权限)注册表
查看>>