gpt4 book ai didi

html - CSS 下拉菜单
  • 堆叠在一起?
  • 转载 作者:太空宇宙 更新时间:2023-11-03 21:53:46 25 4
    gpt4 key购买 nike

    我正在构建一个 css 下拉菜单,当我将鼠标悬停在我的 div 上时,li 标签会相互堆叠,您可以明白我的意思 - JSFiddle我不确定我的 CSS 在我定位东西的方式上是否正确。

    这里还有一些代码:

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>
    <link rel="stylesheet" href="Assets/StyleSheets/StyleSheet.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Shirt Happens</title>

    <script type="text/javascript">

    </script>

    <style type="text/css">
    .Item {
    float:left;
    position:relative;
    }

    .Item > ul li {
    z-index:1000;
    float:left;
    padding:10px 15px;
    margin:2px 0 0;
    list-style:none;
    background-color:#FFF;
    border:1px solid #CCC;
    border:1px solid rgba(0, 0, 0, 0.2);
    -webkit-box-shadow:0 5px 10px rgba(0, 0, 0, 0.2);
    -moz-box-shadow:0 5px 10px rgba(0, 0, 0, 0.2);
    box-shadow:0 5px 10px rgba(0, 0, 0, 0.2);
    -webkit-background-clip:padding-box;
    -moz-background-clip:padding;
    background-clip:padding-box;
    }

    .Item ul li:hover .MenuItem {
    border-bottom:3px solid #F00;
    background-color:#EEE;
    color:rgb(50,50,50);
    }

    .Item > ul li:after,
    .Item > ul li::after {
    position:absolute;
    top:-8px;
    right:20px;
    content:'';
    width:0;
    height:0;
    border-bottom:solid 8px #FFF;
    border-left:solid 8px transparent;
    border-right:solid 8px transparent;
    }

    .Item > ul li:before,
    .Item > ul li::before {
    position:absolute;
    top:-9px;
    right:19px;
    content:'';
    width:0;
    height:0;
    border-bottom:solid 9px #CCC;
    border-left:solid 9px transparent;
    border-right:solid 9px transparent;
    }

    .Item > ul li {
    display:none;
    position:absolute;
    top:80px;
    right:0px;
    }

    .Item:hover > ul li {
    display:block;
    }

    .MenuItem {
    text-transform:uppercase;
    font-weight:bold;
    color:#777;
    height:80px;
    padding:0 15px;
    text-align:center;
    cursor:pointer;
    line-height:80px;
    transition:all .15s ease-in-out;
    -webkit-transition:all .15s ease-in-out;
    -moz-transition:all .15s ease-in-out;
    -ms-transition:all .15s ease-in-out;
    -o-transition:all .15s ease-in-out;
    color:rgb(105,105,105);
    position:relative;
    }

    .MenuItem:hover {
    border-bottom:3px solid #F00;
    background-color:#EEE;
    color:rgb(50,50,50);
    }

    .Triangle {
    width:0;
    height:0;
    border-left:8px solid transparent;
    border-right:8px solid transparent;
    border-top:8px solid rgb(105,105,105);
    }
    </style>
    </head>

    <body>
    <div id="Wrapper">
    <div id="Header">
    <div id="HeaderC">
    <div id="Logo"></div>

    <div id="Menu">
    <div class="Item">
    <div class="MenuItem icon-down-open">Menu Item 1</div>

    <ul>
    <li>Inside Item</li>
    <li>Inside Item</li>
    <li>Inside Item</li>
    </ul>
    </div>
    <div class="Item">
    <div class="MenuItem icon-down-open">Menu Item 1</div>

    <ul>
    <li>Inside Item</li>
    </ul>
    </div>
    <div class="Item">
    <div class="MenuItem icon-down-open">Menu Item 1</div>

    <ul>
    <li>Inside Item</li>
    </ul>
    </div>
    </div>
    </div>
    </div>

    <div id="Middle">
    <div id="MiddleC"></div>
    <!--Middle Content-->
    </div>

    <div id="Footer">
    <div id="FooterC"></div>
    <!--Footer Content-->
    </div>
    </div>
    </body>
    </html>

    最佳答案

    问题是您正在使用此选择器:.item > ul li 将所有这些列表项设置为具有相对于其父级完全相同的顶部和右侧位置的绝对位置.item 容器。改变这个:

    .Item > ul li {
    display:none;
    position:absolute;
    top:80px;
    right:0px;
    }

    对此:

    .Item > ul li {
    display:none;
    position:relative;
    top:-12px;
    right:0;
    }

    关于html - CSS 下拉菜单 <li> 堆叠在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15399374/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com