Make CSS Drop Down Menu 2 Columns

2019-02-07 01:04发布

I currently have a css <ul><li> dropdown menu that uses the following code. Unfortunately I want the sub menus to display in 2 columns as there are about 16 items in that submenu. Does anyone know how to use the following code to make this drop down menu 2 columns?

.menu{
    border:none;
    border:0px;
    margin:0px;
    padding:0px;
    font: 67.5% "Lucida Sans Unicode", "Bitstream Vera Sans", "Trebuchet Unicode MS", "Lucida Grande", Verdana, Helvetica, sans-serif;
    font-size:18px;
    font-weight:bold;
}
.menu ul{
    background:#006633;
    height:35px;
    list-style:none;
    margin:0;
    padding:0;
}
.menu li{
    float:left;
    padding:0px;
}
.menu li a{
    background:#006633 url("../images/seperator.gif") bottom right no-repeat;
    color:#ffffff;
    display:block;
    font-weight:normal;
    line-height:35px;
    margin:0px;
    padding:0px 25px;
    text-align:center;
    text-decoration:none;
}
.menu li a:hover, .menu ul li:hover a{
    background: #003f20 url("../images/hover.gif") bottom center no-repeat;
    color:#FFFFFF;
    text-decoration:none;
}
.menu li ul{
    background:#006633;
    display:none;
    height:auto;
    padding:0px;
    margin:0px;
    border:0px;
    position:absolute;
    width:225px;
    z-index:200;
    /*top:1em;
    /*left:0;*/
}
.menu li:hover ul{
    display:block;
}
.menu li li {
    background:url('../images/sub_sep.gif') bottom left no-repeat;
    display:block;
    float:none;
    margin:0px;
    padding:0px;
    width:225px;
}
.menu li:hover li a{
    background:none;
}
.menu li ul a{
    display:block;
    height:30px;
    font-size:12px;
    font-style:normal;
    margin:0px;
    padding:0px 10px 0px 15px;
    text-align:left;
}
.menu li ul a:hover, .menu li ul li:hover a{
    background:#003f20 url('../images/hover_sub.gif') center left no-repeat;
    border:0px;
    color:#ffffff;
    text-decoration:none;
}
.menu p{
    clear:left;
}

3条回答
▲ chillily
2楼-- · 2019-02-07 01:34

2018 edit

Hey, 7 years later the columns css property is well supported

ul{
  columns: 2;
}
<ul>
  <li>first item</li>
  <li>second item</li>
  <li>third item</li>
  <li>fourth item</li>
  <li>fifth item</li>
</ul>

You could probably get a similar effect with the very robust grid


2011 original answer

Make the ul twice as wide as the li's and float the li's left

http://www.behemothdan.com/2011/05/faux-mega-menu-in-wordpress/

查看更多
虎瘦雄心在
3楼-- · 2019-02-07 01:40

I have just wrote a short tute on that http://www.prowebdesign.ro/wordpress-sub-menu-items-split-in-2-columns-the-easy-way/. Basically, it expands the answer of Michael Jasper, but offers a tad more flexibility: you can have 2 columns for selected sub-menus only.

查看更多
做自己的国王
4楼-- · 2019-02-07 01:48

To make the listings display alpha down instead of across, wrap half of the <li>'s in a div, and the other half in another div. Then float the divs left.

查看更多
登录 后发表回答