2301_78200098 2023-12-01 19:27 采纳率: 0%
浏览 1

实现商品菜单的二级菜单显示

谁能实现二级菜单的显示过后的那种样式啊 本人把字加进去过后他的样式也跟着导航条的样式变了

img


```javascript
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .content{
            width:80%;
            height:500px;
            margin:20px auto;
        }
        ul{
            list-style: none;
            width:100%;
            height:30px;
            background-color: saddlebrown;
            position: relative;
        }
        ul li{
            width:9%;
            height: 30px;
            line-height: 30px;
            background-color: rgb(44,19,1);
            float:left;
            margin-left:1px;
            text-align: center;
            color:white;
            font-size:14px;
        }
        ul li a{
            text-decoration: none;   
        }
        .box{
            display: none;
            width:800px;
            height:400px;
            border:2px solid rgb(44,19,1);
            color:black;
            position: absolute;
            top:30px;
            left:40px;
        }
        .box ul li{
            background-color: white;
            list-style: none;
        }
        .rm{
            font-weight: bold;
            color:orange;
        }
    </style>
    <script src="js/jquery-3.3.1.min.js"></script>
    <script>
        $(function(){
            $("ul li").each(function(index){
                $(this).mousemove(function(){
                   $(this).children().show();
                   $(this).css({"background-color":"white","color":"rgb(44,19,1)","border":"2px solid rgb(44,19,1)"});
                });
                $(this).mouseout(function(){
                   $(this).children().hide();
                  $(this).css({"background-color":"rgb(44,19,1)","color":"white","border":"2px solid rgb(44,19,1)"});
                });
            });
        });
    </script>
</head>
<body>
    <div class="content">
        <ul>
            <li>
               首页
                <div class="box">
                    <ul>
                        <li><span class="rm">热门:</span></li>
                        <li><span>秋冬新品</span></li>
                        <li>雪地靴</li>
                        <li>满帮</li>
                        <li>及踝靴</li>
                        <li>短靴</li>
                        <li>中靴</li>
                        <li>长靴</li>
                        <li><span>断码特价</span></li>
                        <li>松糕鞋</li>
                        <li>毛靴</li>
                        <li>高筒靴</li>
                    </ul>
                   


                </div>
            </li>
            <li>女鞋馆 <div class="box">
                测试2
            </div></li>
            <li>男鞋馆<div class="box">
                测试3
            </div></li>
            <li>女装馆<div class="box">
                测试4
            </div></li>
            <li>男装馆 <div class="box">
                测试5
            </div></li>
            <li>箱包馆 <div class="box">
                测试6
            </div></li>
            <li>儿童馆 <div class="box">
                测试7
            </div></li>
            <li>户外馆 <div class="box">
                测试8
            </div></li>
            <li>运动馆 <div class="box">
                测试9
            </div></li>
        </ul>
    </div>
</body>
</html>


























  • 写回答

3条回答 默认 最新

  • 梦回阑珊 2023-12-01 20:32
    关注

    回复不易,麻烦关注下博主,后面还有问题直接私信我,谢谢!!!

    你的代码已经实现了当鼠标悬停在导航条的某个菜单项上时,显示相应的二级菜单。然而,你可能想要调整一些样式以确保在鼠标悬停时更清晰地显示二级菜单。

    我对你的代码进行了一些调整,包括:

    调整二级菜单的位置,使其相对于导航条的父项显示。
    为二级菜单增加背景颜色,以使其与导航条区分开。
    使用CSS伪类 :hover 来简化鼠标悬停时的样式设置。
    以下是修改后的代码:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            .content {
                width: 80%;
                height: 500px;
                margin: 20px auto;
            }
    
            ul {
                list-style: none;
                width: 100%;
                height: 30px;
                background-color: saddlebrown;
                position: relative;
            }
    
            ul li {
                width: 9%;
                height: 30px;
                line-height: 30px;
                background-color: rgb(44, 19, 1);
                float: left;
                margin-left: 1px;
                text-align: center;
                color: white;
                font-size: 14px;
                position: relative;
            }
    
            ul li a {
                text-decoration: none;
                color: inherit;
            }
    
            .box {
                display: none;
                width: 200px;
                border: 2px solid rgb(44, 19, 1);
                color: black;
                position: absolute;
                top: 30px;
                left: 0;
                background-color: white;
                z-index: 1;
            }
    
            .box ul li {
                list-style: none;
                padding: 5px;
                border-bottom: 1px solid #ccc;
            }
    
            .box a {
                text-decoration: none;
                color: black;
            }
    
            ul li:hover {
                background-color: white;
                color: rgb(44, 19, 1);
                border: 2px solid rgb(44, 19, 1);
            }
    
            ul li:hover .box {
                display: block;
            }
    
            .rm {
                font-weight: bold;
                color: orange;
            }
        </style>
        <script src="js/jquery-3.3.1.min.js"></script>
        <script>
            $(function () {
                $("ul li").each(function (index) {
                    $(this).mousemove(function () {
                        $(this).children().show();
                    });
                    $(this).mouseout(function () {
                        $(this).children().hide();
                    });
                });
            });
        </script>
    </head>
    <body>
    <div class="content">
        <ul>
            <li>
                <a href="#">首页</a>
                <div class="box">
                    <ul>
                        <li><span class="rm">热门:</span></li>
                        <li><a href="#">秋冬新品</a></li>
                        <li><a href="#">雪地靴</a></li>
                        <!-- 其他二级菜单项 -->
                    </ul>
                </div>
            </li>
            <!-- 其他一级菜单项 -->
        </ul>
    </div>
    </body>
    </html>
    
    
    

    这些调整应该能够让你更好地看到悬停在导航菜单项上时的效果,使二级菜单更清晰可见。你可以根据需要进一步调整样式

    评论

报告相同问题?

问题事件

  • 修改了问题 12月1日
  • 创建了问题 12月1日

悬赏问题

  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中
  • ¥15 请各位帮我看看是哪里出了问题
  • ¥15 vs2019的js智能提示
  • ¥15 关于#开发语言#的问题:FDTD建模问题图中代码没有报错,但是模型却变透明了
  • ¥15 uniapp的h5项目写一个抽奖动画
  • ¥15 hadoop中启动hive报错如下怎么解决