带子菜单的堆叠菜单,需要更改子菜单的宽度

时间:2017-03-22 07:18:23

标签: html5 twitter-bootstrap css3 menu collapse

我是非常新的。我有一个带子菜单的堆叠菜单,但是我需要子菜单的宽度小于菜单,每次我更改子菜单的宽度时它会改变,但也保持父菜单的宽度

[这是子菜单的外观1

HTML

`<div class="row">
        <div class="col-md-3">
            <ul class="menu">
                <li><a href="trucks.html" target="preview-iframe">Book Trucks</a></li>
                <li class="active"> <a href="schedule.html" target="preview-iframe" data-toggle="collapse" data-target="#toggle1" class="collapsed">Schedule <i class="fa fa-angle-down" aria-hidden="true"></i>
                </a>
                    <div class="collapse" id="toggle1">
                        <ul class="menu-list">
                            <li><a href="start.html" target="preview-iframe"> Start Date</a></li>
                            <li><a href="end.html" target="preview-iframe"> End Date</a></li>
                        </ul>
                <li class="active"> <a href="routes.html" target="preview-iframe" data-toggle="collapse" data-target="#toggle" class="collapsed">Routes <i class="fa fa-angle-down" aria-hidden="true"></i>
                </a>
                    <div class="collapse" id="toggle">
                        <ul class="menu-list">
                            <li><a href="routes2.html" target="preview-iframe">Route 2</a></li>
                            <li><a href="routes3.html" target="preview-iframe">Route 3</a></li>
                            <li><a href="routes4.html" target="preview-iframe">Route 4</a></li>
                            <li><a href="routes5.html" target="preview-iframe">Route 5</a></li>
                        </ul>
                    </div>
                </li>
                <li><a href="region.html" target="preview-iframe">Availability Regions</a></li>
        </div>`




CSS
    /* MENU */
    @media (min-width: 768px) {
        .menu {
            width:72.5%;
            left: 100px;
            border: 1px solid #129cf3;
            position: absolute;
            background-color: #f2f2f2;
            font: 18px 'Raleway', sans-serif;
            text-align: center;
            text-decoration: none;
            border-collapse: collapse;
            top: 250px;
            font-weight: 600;
            border-bottom: none;
            transition: all 1s;
            box-shadow: 10px 10px 5px #888888;
        }
        .menu li {
            list-style: none;
            text-decoration: none;
        }
    }
    .menu a {
        color: #000;
        left: 800px;
        text-transform: uppercase;
        letter-spacing: .1em;
        text-decoration: none;
        display: block;
        padding: 35px;
        border-bottom: 1px solid #129cf3;
        text-align: center;
        border-collapse: collapse;
        transition: all 1s;
    }
    .menu a:hover {
        background-color: #129cf3;
        color: #000;
        text-decoration: none;
    }
    .menu i {
        font-weight: 600;
    }

    #toggle,menu:before
    #toggle:after{
        width 50%;
    }

  .menu-list li a{
        margin-left: 20px;
        margin-right: 20px;
        margin-bottom:0px;
        margin-top: 0px;
        padding: 15px;
        border: 0px;
        font-size: 12px;
        text-align: center;
    }

https://jsfiddle.net/cnezagf0/

1 个答案:

答案 0 :(得分:0)

这将是css     / * MENU * /

   ul{

      list-style:none;
      padding:0;margin:0;
    }
    @media (min-width: 768px) {
        .menu {
            width:72.5%;
            left: 100px;
            border: 1px solid #129cf3;
            position: relatve;
            background-color: #f2f2f2;
            font: 18px 'Raleway', sans-serif;
            text-align: center;
            text-decoration: none;
            border-collapse: collapse;
            top: 250px;
            font-weight: 600;
            border-bottom: none;
            transition: all 1s;
            box-shadow: 10px 10px 5px #888888;
        }
        .menu>li {
            list-style: none;
            text-decoration: none;
        }
    }
    .menu >li>a {
        color: #000;
        left: 800px;
        text-transform: uppercase;
        letter-spacing: .1em;
        text-decoration: none;
        display: block;
        padding: 35px;
        border-bottom: 1px solid #129cf3;
        text-align: center;
        border-collapse: collapse;
        transition: all 1s;
    }
    .menu >li> a:hover {
        background-color: #129cf3;
        color: #000;
        text-decoration: none;
    }
    .menu i {
        font-weight: 600;
    }

    #toggle,menu:before
    #toggle:after{
        width 50%;
    }

  .menu-list >li >a{
     margin: 0 auto;
    padding: 15px;
    border: 0px;
    font-size: 12px;
    text-align: center;
    color: #000;
   text-transform: uppercase;
    letter-spacing: .1em;
    text-decoration: none;
    text-align: center;
    width: 80%;
    background: red;
    display: block;

    }

和fiddler link https://jsfiddle.net/zsL2d92y/1/