RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1081004
Accepted
ioprst
ioprst
Asked:2020-02-11 15:24:34 +0000 UTC2020-02-11 15:24:34 +0000 UTC 2020-02-11 15:24:34 +0000 UTC

将子菜单块拉伸到嵌套元素的最大宽度

  • 772

您需要将嵌套菜单块拉伸到等于最大嵌套元素宽度的宽度(在本例中<li><a>Text<a/></li>)。

* {
    margin:0;
    padding:0;
}

html, body {
  height: 100%;
}

.wrapper {
  height: 100%;
  display: table;
  width: 100%;
}

.header {
  display: table-row;
  height: 0;
}

.main {
  height: 100%;
  display: table;
  width: 100%;
}

.horizontalbar {
  display: table-row;
  height: 0;
}

.box {
  display: table-cell;
}

.sidebar {
  width: 0;
}

.content {
  height: 100%;
}

.content object {
  width: 100%;
  height: 100%;
  border: none;
  margin: 0;
  padding: 0;
  display: block;
}

.footer {
  display: table-row;
  height: 0;
}

/*
header
*/

nav {
    width: 100%;
    /*margin: 0 auto 30px;*/
    margin: 0 auto 0;
}

ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.topmenu > li {
    display: inline-block;
    margin-right: 20px;
    position: relative;
}

.topmenu > li:last-child {
    margin-right: 0;
}

a {
    display: block;
    padding: 10px 15px;
    text-decoration: none;
    outline: none;
    transition: .5s linear;
}

/*.fa {*/
/*    color: inherit;*/
/*    padding-left: 10px;*/
/*}*/

.submenu {
    position: absolute;
    top: 100%;
    left: 0;
    width: 100%;
    z-index: 10;
    -webkit-transition: 0.5s ease-in-out;
    -moz-transition: 0.5s ease-in-out;
    -o-transition: 0.5s ease-in-out;
    transition: 0.5s ease-in-out;
}

.menubar ul {
    background: #00d3ec;
}

.menubar ul a {
    color: #695753;
}

.menubar .submenu {
    display: none;
    background: #00d3ec;
}

.menubar ul li:hover .submenu {
    display: block;
}

.submenu li a {
    border-bottom: 1px solid rgba(255,255,255,.3);
    color: #695753;
}
<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>Tmp</title>
    <link rel="stylesheet" href="/static/css/style.css">
</head>
<body bgcolor="#FFFFFF">
    <div class="wrapper">
        <div class="header">
            <nav class="menubar">
                <ul class="topmenu">
                    <li><a href="/">Домой</a></li>
                    <li><a href="#">Проекты</a>
                        <ul class="submenu">
                            <li><a href="#">Test</a></li>
                            <li><a href="#">TestTestTestTestTest</a></li>
                        </ul>
                    </li>
                    <li><a href="#">Пользователь</a></li>
                    <li><a href="/logout/">Выход</a></li>
                </ul>
            </nav>
        </div>
    </div>
</body>
</html>

请参阅“项目”下的子菜单。

如何使菜单填充完全覆盖 TestTestTestTestTest 项(=> 第一项的背景也增加)?

html
  • 1 1 个回答
  • 10 Views

1 个回答

  • Voted
  1. Best Answer
    adudnik.ru
    2020-02-11T15:32:50Z2020-02-11T15:32:50Z

    删除width:100%并替换为width:auto;

    对于绝对元素width:100%,这是相对定位的父项的宽度(即,在您的情况下,是“项目”项的宽度)。

    是的,第一段的背景也增加了,因为 这不是第一个背景li,而是整个容器ul里面的所有东西li。

    * {
        margin:0;
        padding:0;
    }
    
    html, body {
      height: 100%;
    }
    
    .wrapper {
      height: 100%;
      display: table;
      width: 100%;
    }
    
    .header {
      display: table-row;
      height: 0;
    }
    
    .main {
      height: 100%;
      display: table;
      width: 100%;
    }
    
    .horizontalbar {
      display: table-row;
      height: 0;
    }
    
    .box {
      display: table-cell;
    }
    
    .sidebar {
      width: 0;
    }
    
    .content {
      height: 100%;
    }
    
    .content object {
      width: 100%;
      height: 100%;
      border: none;
      margin: 0;
      padding: 0;
      display: block;
    }
    
    .footer {
      display: table-row;
      height: 0;
    }
    
    /*
    header
    */
    
    nav {
        width: 100%;
        /*margin: 0 auto 30px;*/
        margin: 0 auto 0;
    }
    
    ul {
        list-style: none;
        margin: 0;
        padding: 0;
    }
    
    .topmenu > li {
        display: inline-block;
        margin-right: 20px;
        position: relative;
    }
    
    .topmenu > li:last-child {
        margin-right: 0;
    }
    
    a {
        display: block;
        padding: 10px 15px;
        text-decoration: none;
        outline: none;
        transition: .5s linear;
    }
    
    /*.fa {*/
    /*    color: inherit;*/
    /*    padding-left: 10px;*/
    /*}*/
    
    .submenu {
        position: absolute;
        top: 100%;
        left: 0;
        width: auto;
        z-index: 10;
        -webkit-transition: 0.5s ease-in-out;
        -moz-transition: 0.5s ease-in-out;
        -o-transition: 0.5s ease-in-out;
        transition: 0.5s ease-in-out;
    }
    
    .menubar ul {
        background: #00d3ec;
    }
    
    .menubar ul a {
        color: #695753;
    }
    
    .menubar .submenu {
        display: none;
        background: #00d3ec;
    }
    
    .menubar ul li:hover .submenu {
        display: block;
    }
    
    .submenu li a {
        border-bottom: 1px solid rgba(255,255,255,.3);
        color: #695753;
    }
    <!DOCTYPE html>
    <html lang="ru">
    <head>
        <meta charset="UTF-8">
        <title>Tmp</title>
        <link rel="stylesheet" href="/static/css/style.css">
    </head>
    <body bgcolor="#FFFFFF">
        <div class="wrapper">
            <div class="header">
                <nav class="menubar">
                    <ul class="topmenu">
                        <li><a href="/">Домой</a></li>
                        <li><a href="#">Проекты</a>
                            <ul class="submenu">
                                <li><a href="#">Test</a></li>
                                <li><a href="#">TestTestTestTestTest</a></li>
                            </ul>
                        </li>
                        <li><a href="#">Пользователь</a></li>
                        <li><a href="/logout/">Выход</a></li>
                    </ul>
                </nav>
            </div>
        </div>
    </body>
    </html>

    • 3

相关问题

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    如何从列表中打印最大元素(str 类型)的长度?

    • 2 个回答
  • Marko Smith

    如何在 PyQT5 中清除 QFrame 的内容

    • 1 个回答
  • Marko Smith

    如何将具有特定字符的字符串拆分为两个不同的列表?

    • 2 个回答
  • Marko Smith

    导航栏活动元素

    • 1 个回答
  • Marko Smith

    是否可以将文本放入数组中?[关闭]

    • 1 个回答
  • Marko Smith

    如何一次用多个分隔符拆分字符串?

    • 1 个回答
  • Marko Smith

    如何通过 ClassPath 创建 InputStream?

    • 2 个回答
  • Marko Smith

    在一个查询中连接多个表

    • 1 个回答
  • Marko Smith

    对列表列表中的所有值求和

    • 3 个回答
  • Marko Smith

    如何对齐 string.Format 中的列?

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5