【问题标题】:drop down menu width arrangement下拉菜单宽度排列
【发布时间】:2012-11-29 04:25:56
【问题描述】:

我有一个宽度为 990 像素的网站可以查看 Click Here。只是我安装了一个多层下拉菜单。如果你在这个网站上看到我在下拉菜单上有 6 个类别,然后是一个空白区域。我希望所有类别都完全排列,没有空间。

我的css代码是

  /* Page */
body,html,div,blockquote,img,label,p,h1,h2,h3,h4,h5,h6,pre,ul,ol,li,dl,dt,dd,form,a,fieldset,input,th,td{border:0;outline:none;margin:0;padding:0;}
ul{list-style:none;}

body {font: normal 13px Arial, sans-serif;}
h2 {font: normal 26px Arial, sans-serif; padding: 20px 0; margin: 0 0 30px 0;}
.wrap {width: 990px; margin: 0 auto;}
.demo-container {padding: 0 0;}
.demo-container h4 {font-size: 14px; margin: 0 0 5px 0;}

/* Mega Menu Styles */
.mega-menu ul, .mega-menu ul li {list-style: none;}
.mega-menu ul {position: relative; padding: 0; margin: 0;}
.mega-menu ul li ul {display: none;}
.mega-menu .sub {display: none;}
.mega-menu .sub ul {display: block;}

#mega-menu-1 {
font: normal 13px Arial, sans-serif; 
list-style: none; 
position: relative; 
padding: 0; 
margin: 0;
}
#mega-menu-1 .sub ul {
display: block;
}
#mega-menu-1 {
background: #222; 
width: 100%; 
height: 40px;
position: relative;
}
#mega-menu-1 li {
float: left; 
margin: 0; 
padding: 0; 
font-weight: bold;
}
#mega-menu-1 li a {
float: left; 
display: block; 
color: #fff; 
padding: 12px 25px; 
background: #222; 
text-decoration: none;
}
#mega-menu-1 li.mega-hover a, #mega-menu-1 li.mega-hover a:hover {
background: #CCC; 
color: #000;
}
#mega-menu-1 li a:hover {
background: #999; 
color: #000;
}
#mega-menu-1 li .sub-container {
position: absolute;
}
#mega-menu-1 li .sub {
background: #efefef; 
padding: 15px; 
border: 1px solid #ccc;
}
#mega-menu-1 li .sub .row {
width: 100%; 
overflow: hidden;
clear: both;
}
#mega-menu-1 li .sub li {
list-style: none; 
float: none; 
width: 170px; 
font-size: 1em; 
font-weight: normal;
}
#mega-menu-1 li .sub li.mega-hdr {
margin: 0 10px 10px 0; 
float: left;
}
#mega-menu-1 li .sub li.mega-hdr.last {
margin-right: 0;
}
#mega-menu-1 li .sub a {
background: none; 
color: #111; 
padding: 7px 10px; 
display: block; 
float: none; 
font-size: 0.9em;
}
#mega-menu-1 li .sub li.mega-hdr a.mega-hdr-a {
padding: 5px 15px; 
margin-bottom: 5px; 
background: #6B6B6B; 
text-transform: uppercase; 
font-weight: bold; 
color: #fff;
}
#mega-menu-1 li .sub li.mega-hdr a.mega-hdr-a:hover {
color: #000;
}
#mega-menu-1 .sub li.mega-hdr li a {
padding: 4px 5px; 
font-weight: normal;
}
#mega-menu-1 .sub li.mega-hdr li a:hover {
color: #a32403; 
background: #efefef;
}
#mega-menu-1 .sub ul li {
padding-right: 0;
}
#mega-menu-1 li .sub-container.non-mega .sub {
padding: 10px;
}
#mega-menu-1 li .sub-container.non-mega li {
padding: 0; 
width: 190px; 
margin: 0;
}
#mega-menu-1 li .sub-container.non-mega li a {
padding: 7px 5px 7px 22px;
}
#mega-menu-1 li .sub-container.non-mega li a:hover {
color: #a32403; 
background: #efefef;
}

我有另一个名为 green.css 的文件,代码如下

.mega-menu ul, .mega-menu ul li {list-style: none;}
.mega-menu ul {position: relative; padding: 0; margin: 0;}
.mega-menu ul li ul {display: none;}
.mega-menu .sub {display: none;}
.mega-menu .sub ul {display: block;}

.green {font: normal 13px Arial, sans-serif; line-height: 16px;}
.green ul.mega-menu, .green ul.mega-menu, .green ul.mega-menu li {margin: 0; padding: 0; border: none;}
.green ul.mega-menu {background: #222 url(images/bg_green.png) repeat-x 0 -80px; width: 100%; height: 40px; border-right: 1px solid #44b3ff; border-left: 1px solid #44b3ff; position: relative;}
.green ul.mega-menu li {float: left; margin: 0; padding: 0; font-size: 13px; font-weight: bold;}
.green ul.mega-menu li a {float: left; display: block; color: #000; padding: 12px 38px 12px 25px; background: url(images/bg_green.png) repeat-x 100% 0; text-shadow: 1px 1px 1px #fff; text-decoration: none;}
.green ul.mega-menu li a.dc-mega {position: relative;}
.green ul.mega-menu li a .dc-mega-icon {display: block; position: absolute; width: 8px; height: 6px;  top: 18px; right: 15px; background: url(images/arrow.png) no-repeat 0 100%;}
.green ul.mega-menu li.mega-hover a, .green ul.mega-menu li a:hover {background-position: 100% -40px; color: #000; text-shadow: none;}
.green ul.mega-menu li.mega-hover a .dc-mega-icon {background-position: 0 100%;}
.green ul.mega-menu li .sub-container {position: absolute; background: url(images/bg_sub_left.png) no-repeat 0 100%; padding-left: 20px; margin-left: -3px;}
.green ul.mega-menu li .sub {background: url(images/bg_sub.png) no-repeat 100% 100%; padding: 20px 20px 20px 10px;}
.green ul.mega-menu li .sub-container.mega .sub {padding: 20px 20px 10px 0;}
.green ul.mega-menu li .sub .row {width: 100%; overflow: hidden; clear: both;}
.green ul.mega-menu li .sub li {list-style: none; float: none; width: 170px; font-size: 1em; font-weight: normal;}
.green ul.mega-menu li .sub li.mega-hdr {margin: 0 10px 10px 0; float: left;}
.green ul.mega-menu li .sub li.mega-hdr.last {margin-right: 0;}
.green ul.mega-menu li .sub a {background: none; border: none; text-shadow: none; color: #111; padding: 7px 10px; display: block; float: none; text-decoration: none; font-size: 0.9em;}
.green ul.mega-menu li .sub li.mega-hdr a.mega-hdr-a {padding: 5px 5px 5px 15px; margin-bottom: 5px; background: #4EC3F3 url(images/bg_mega_hdr.png) no-repeat 0 0; text-transform: uppercase; font-weight: bold; color: #000; text-shadow: 1px 1px 1px #fff;}
.green ul.mega-menu li .sub li.mega-hdr a.mega-hdr-a:hover {color: #fff; text-shadow: none;}
.green ul.mega-menu .sub li.mega-hdr li a {padding: 4px 5px 4px 20px; background: url(images/arrow_off.png) no-repeat 5px 8px; font-weight: normal;}
.green ul.mega-menu .sub li.mega-hdr li a:hover {color: #a32403; background: #efefef url(images/arrow_on.png) no-repeat 5px 8px;}
.green ul.mega-menu .sub ul li {padding-right: 0;}
.green ul.mega-menu li .sub-container.non-mega .sub {padding: 20px 20px 20px 0;}
.green ul.mega-menu li .sub-container.non-mega li {padding: 0; width: 190px; margin: 0;}
.green ul.mega-menu li .sub-container.non-mega li a {padding: 7px 5px 7px 22px; background: url(images/arrow_off.png) no-repeat 7px 10px;}
.green ul.mega-menu li .sub-container.non-mega li a:hover {color: #a32403; background: #efefef url(images/arrow_on.png) no-repeat 7px 10px;}

请建议我如何解决这个问题..谢谢...

【问题讨论】:

    标签: css drop-down-menu menu


    【解决方案1】:
    .green ul.mega-menu li a {
    float: left;
    display: block;
    color: black;
    padding: 12px 38px 12px 25px;
    background: url(images/bg_green.png) repeat-x 100% 0;
    text-shadow: 1px 1px 1px white;
    text-decoration: none;
    width: 102px;
    text-align: center;
    }
    

    而不是你已经拥有的

    然后是一个小的 jquery 插件来删除最后一个拆分器

    $('.green ul.mega-menu li:last-child a').css('background','none');
    

    编辑以获得更好看的按钮

    .green ul.mega-menu li a .dc-mega-icon {
    display: block;
    position: absolute;
    width: 8px;
    height: 6px;
    top: 18px;
    right: 12%;
    background: url(images/arrow.png) no-repeat 0 100%;
    }
    

    编辑回复使用以下 css

    .green {font: normal 13px Arial, sans-serif; line-height: 16px;}
    .green ul.mega-menu, .green ul.mega-menu, .green ul.mega-menu li {margin: 0; padding: 0; border: none;}
    .green ul.mega-menu {background: #222 url(images/bg_green.png) repeat-x 0 -80px; width: 100%; height: 40px; border-right: 1px solid #44b3ff; border-left: 1px solid #44b3ff; position: relative;}
    .green ul.mega-menu li {float: left; margin: 0; padding: 0; font-size: 13px; font-weight: bold;}
    .green ul.mega-menu li a {float: left; display: block; color: black; padding: 12px 38px 12px 25px; background: url(images/bg_green.png) repeat-x 100% 0; text-shadow: 1px 1px 1px white; text-decoration: none; width: 102px; text-align: center;}
    .green ul.mega-menu li a.dc-mega {position: relative;}
    .green ul.mega-menu li a .dc-mega-icon {display: block; position: absolute; width: 8px; height: 6px; top: 18px; right: 12%; background: url(images/arrow.png) no-repeat 0 100%;}
    .green ul.mega-menu li.mega-hover a, .green ul.mega-menu li a:hover {background-position: 100% -40px; color: #000; text-shadow: none;}
    .green ul.mega-menu li.mega-hover a .dc-mega-icon {background-position: 0 100%;}
    .green ul.mega-menu li .sub-container {position: absolute; background: url(images/bg_sub_left.png) no-repeat 0 100%; padding-left: 20px; margin-left: -3px;}
    .green ul.mega-menu li .sub {background: url(images/bg_sub.png) no-repeat 100% 100%; padding: 20px 20px 20px 10px;}
    .green ul.mega-menu li .sub-container.mega .sub {padding: 20px 20px 10px 0;}
    .green ul.mega-menu li .sub .row {width: 100%; overflow: hidden; clear: both;}
    .green ul.mega-menu li .sub li {list-style: none; float: none; width: 170px; font-size: 1em; font-weight: normal;}
    .green ul.mega-menu li .sub li.mega-hdr {margin: 0 10px 10px 0; float: left;}
    .green ul.mega-menu li .sub li.mega-hdr.last {margin-right: 0;}
    .green ul.mega-menu li .sub a {background: none; border: none; text-shadow: none; color: #111; padding: 7px 10px; display: block; float: none; text-decoration: none; font-size: 0.9em;}
    .green ul.mega-menu li .sub li.mega-hdr a.mega-hdr-a {padding: 5px 5px 5px 15px; margin-bottom: 5px; background: #4EC3F3 url(images/bg_mega_hdr.png) no-repeat 0 0; text-transform: uppercase; font-weight: bold; color: #000; text-shadow: 1px 1px 1px #fff;}
    .green ul.mega-menu li .sub li.mega-hdr a.mega-hdr-a:hover {color: #fff; text-shadow: none;}
    .green ul.mega-menu .sub li.mega-hdr li a {padding: 4px 5px 4px 20px; background: url(images/arrow_off.png) no-repeat 5px 8px; font-weight: normal;}
    .green ul.mega-menu .sub li.mega-hdr li a:hover {color: #a32403; background: #efefef url(images/arrow_on.png) no-repeat 5px 8px;}
    .green ul.mega-menu .sub ul li {padding-right: 0;}
    .green ul.mega-menu li .sub-container.non-mega .sub {padding: 20px 20px 20px 0;}
    .green ul.mega-menu li .sub-container.non-mega li {padding: 0; width: 190px; margin: 0;}
    .green ul.mega-menu li .sub-container.non-mega li a {padding: 7px 5px 7px 22px; background: url(images/arrow_off.png) no-repeat 7px 10px;}
    .green ul.mega-menu li .sub-container.non-mega li a:hover {color: #a32403; background: #efefef url(images/arrow_on.png) no-repeat 7px 10px;}
    

    【讨论】:

    • 我添加了另一个名为 green.css 的文件。你能看看这个吗?感谢您的支持。
    • 我已经编辑了文件尝试用你的绿色css覆盖这个部分,所以它的外观 - 它应该看起来如何(查看我的编辑与底部的img
    • wowwwwwwwwwwwwwwww 很多很多谢谢亲爱的..它的工作很好..爱你..上帝保佑你..
    • 亲爱的你有没有看到一些按钮文本是在两行中..如果你点击社区,“创建社区”是在两行中..我们可以在一行中完成所有这些
    【解决方案2】:

    你可以添加

    display: table; 
    

    到 ul 和

    display: table-cell; 
    

    到 lis 而不是浮动。

    这会导致类似:

    .green ul.mega-menu {
        display: table;
    }
    .green ul.mega-menu li {
        display: table-cell;
        float: none;
    }
    

    顺便说一句:你真的认为选框是个好主意吗?

    【讨论】:

    • 如果不是你有任何吸引人的想法。 ??你的意思是我必须将显示更改为表格单元格?你能把代码发给我吗
    • 选框不会吸引人,只会分散注意力。
    • 我添加了另一个名为 green.css 的文件。你能看看这个吗?另外,如果您有更好的想法,请告诉我哪个更容易吸引用户。
    • 你能告诉我选框的替代方案吗,拜托..我想让人们看到一个点l
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多