jjw

写给自己的博客。 记录学习的点滴以备查。
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

css 练手 下拉菜单

Posted on 2022-02-15 23:00  jjw  阅读(40)  评论(0编辑  收藏  举报
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title></title>
    <style>
        .box {
            display: flex;
            width: 300px;
            border: 1px solid red;
            justify-content: space-evenly;
        }

        .item {
            position: relative;
            border: 1px solid blue;
        }

        .item>div {
            height: 30px;
            line-height: 30px;
        }        

        ul {
            list-style: none;
            position: absolute;
            display: none;
            padding: 0;
            margin: 0;
            width: 100px;
            border: 1px solid green;
            top: 30px;
            left: calc((100% - 100px) / 2);
        }

        li {
            padding: 0;
            margin: 0;
        }

        .item:hover>div+ul {
            background-color: red;
            display: block;

        }


    </style>
  </head>
  <body>
    <div class="box">
        <div class="item">
            <div>menuitem1</div>
            <ul>
                <li>item1</li>
                <li>item2</li>
                <li>item3</li>
            </ul>
        </div>
        <div class="item">
            <div>menuitem1</div>
            <ul>
                <li>item1</li>
                <li>item2</li>
                <li>item3</li>
            </ul>
        </div>
    </div>
  </body>
</html>