如何在菜单中创建列表? [英] How to style a list within a menu?

查看:126
本文介绍了如何在菜单中创建列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请将鼠标悬停在菜单中的 更多 按钮: http://jsfiddle.net/XHard/1/ 你会看到有一个列表,其中包含单词 新干净列表 。我想为该列表设置样式,但是因为它在菜单中,它已经有一个样式。

Please hover your mouse over the MORE button in the menu here: http://jsfiddle.net/XHard/1/ You will see that there is a list containing the words New clean list. I want to style that list but because it is inside the menu, it already has a styling to it.

我想为它创建一个新的干净样式,但找不到一种方法。我试过玩过 #mega moreleftbar a ,但是原来的菜单列表样式仍然存在。

I want to create a new clean style for it but cannot find a way to do it. I tried playing around with #mega moreleftbar a but the original menu list styling is still there.

有没有为了在该菜单中列出一个新的清洁样式?

Is there a way to make a new clean styling for a list inside that menu?

这是HTML的一部分:

Here is part of my HTML:

<div id="second-menu" class="clearfix">
    <ul id="secondary-menu" class="nav sf-js-enabled">
        <li class="manimation"><a href="" style="width:400px;border-bottom:9px solid #43cf61">Animation</a></li>
    </ul>

    <ul id="mega">
        <li class="dif mmore" style="background:none;"><a href="#" style="font-style:italic;border-bottom:9px solid #4b5571">More...</a>
            <div>
                <moretopbar>
                    <ul>
                        <li class="mgames"><a href="" style="border-bottom:9px solid #e34328">Games</a></li>
                        <li class="mliterature"><a href="" style="border-bottom:9px solid #2c8f83">Literature</a></li>
                        <li class="marts"><a href="" style="border-bottom:9px solid #cc226a">Arts</a></li>
                        <li class="mcontact" style="background:none;"><a href="" style="border-bottom:9px solid #9395aa">Contact</a></li>
                    </ul>
                </moretopbar>

                <morecontainer>
                    <moreleftbar>

                        <ul>
                            <li><a href="">New clean list 1</a></li>
                            <li><a href="">New clean list 2</a></li>
                            <li><a href="">New clean list 3</a></li>
                            <li><a href="">New clean list 4</a></li>
                        </ul>

                    </moreleftbar>
                </morecontainer>


            </div>
        </li>
    </ul>
</div> <!-- end #second-menu -->

这是我的CSS的一部分:

Here is part of my CSS:

ul#top-menu li { padding-right: 2px; background: url(images/menu-bg.png) repeat-y top right; }
    ul#top-menu a { font-size: 11px; color: #ffffff; text-decoration: none; text-transform: uppercase; font-weight: bold; text-shadow: 1px 1px 1px rgba(0,0,0,0.7); padding: 16px 12px 10px; }
    ul#top-menu a:hover { color: #ebbe5e;}
    ul#top-menu > li.current_page_item > a { color: #ebbe5e !important; }

    ul#top-menu li ul, #mobile_menu { width: 170px !important; padding: 0; background: #161616 url(images/header-bg.png); top: 45px !important; -moz-box-shadow:3px 3px 7px 1px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 3px 3px 7px 1px rgba(0, 0, 0, 0.1); box-shadow: 3px 3px 7px 1px rgba(0, 0, 0, 0.1); -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; border-top-left-radius: 0px;-moz-border-radius-topleft: 0px; border-top-right-radius: 0px; -webkit-border-top-left-radius: 0px; -moz-border-radius-topright: 0px; -webkit-border-top-right-radius: 0px; z-index: 9999px; display: none; }
        ul#top-menu ul li, #mobile_menu li a { margin: 0 !important; padding: 10px 7px 10px 25px !important; background: url(images/top-menu-separator.png) repeat-x; }
        ul#top-menu ul li.first-item { background: none; }
            ul#top-menu ul li a, #mobile_menu a { padding: 0 !important; width: 138px; }

            ul#top-menu li:hover ul ul, ul#top-menu li.sfHover ul ul { top: -1px !important; left: 171px !important; -moz-border-radius: 8px; -webkit-border-radius: 8px; border-radius: 8px; }

    ul#top-menu li.menu-gradient { background: url("images/top-shadow.png") repeat-x; position: absolute; top: 0; left: 0; width: 202px; height: 7px !important; }

ul#secondary-menu li { background: url(images/secondary-menu-bg.png) repeat-y top right; }
    ul#secondary-menu a { font-size: 16px; color: #48423f; text-decoration: none; text-transform: uppercase; font-weight: bold; padding: 22px 16px; }
    ul#secondary-menu a:hover { color: #ffffff; text-shadow: 1px 1px 0 #404747; }
    #second-menu ul.nav li:hover a {color: #ffffff; text-shadow: 1px 1px 0 #404747; }

    ul#secondary-menu > li.current_page_item > a { color: #919e9e !important; }    

    ul#secondary-menu li ul, #category_mobile_menu { width: 360px !important; padding: 7px 0 10px; background: #fff url(images/content-bg.png); top: 55px !important; -moz-box-shadow:3px 3px 7px 1px rgba(0, 0, 0, 0.1); -webkit-box-shadow: 3px 3px 7px 1px rgba(0, 0, 0, 0.1); box-shadow: 3px 3px 7px 1px rgba(0, 0, 0, 0.1); -moz-border-radius: 10px; -webkit-border-radius: 10px; border-radius: 10px; border-top-left-radius: 0px;-moz-border-radius-topleft: 0px; border-top-right-radius: 0px; -webkit-border-top-left-radius: 0px; -moz-border-radius-topright: 0px; -webkit-border-top-right-radius: 0px; z-index: 9999px; display: none; }
        ul#secondary-menu ul li, #category_mobile_menu li a { margin: 0 !important; padding: 8px 0 8px 30px !important; width: 150px; float: left; }
            ul#secondary-menu ul li a, #category_mobile_menu a { padding: 0 !important; }

            ul#secondary-menu li:hover ul ul, ul#secondary-menu li.sfHover ul ul { top: -8px !important; left: 180px !important; -moz-border-radius: 8px; -webkit-border-radius: 8px; border-radius: 8px; }
            ul#secondary-menu ul li.even-item { background: none; }


.manimation:hover{
    background:#43cf61 !important;
}
.mmore:hover{
    background:#4b5571 !important;
}
.mliterature:hover{
    background:#2c8f83 !important;
}
.mgames:hover{
    background:#e34328 !important;
}
.marts:hover{
    background:#cc226a !important;
}
.mcontact:hover{
    background:#9395aa !important;
}

/* ---------- Mega Drop Down --------- */
ul#mega li { padding-right: 0px; background: url(images/secondary-menu-bg.png) repeat-y top right; }

#mega {
list-style:none;
font-weight:bold;
height:2em;

}
#mega li {
padding: 23px 0px;
background:#999;
border:0px solid #000;
float:left;
text-align:center;
position:relative;
}
#mega li:hover {
background:#eee;
border-bottom:0; /* border-bottom:0; and padding-bottom:1px; keeps <li> and <div> connected */
z-index:1; /* shadow above adjacent li */

}
#mega a { font-size: 16px; color: #48423f; text-decoration: none; text-transform: uppercase; font-weight: bold; padding: 22px 16px;}

ul#mega a:hover { color: #FFFFFF; text-shadow: 1px 1px 0 #404747; }



/* ----------- Hide/Show Div ---------- */
#mega div {
    -moz-border-bottom-colors: none;
    -moz-border-image: none;
    -moz-border-left-colors: none;
    -moz-border-right-colors: none;
    -moz-border-top-colors: none;
    background: none repeat scroll 0 0 #FFFFFF;
    border-color: -moz-use-text-color #48423F #48423F;
    border-right: 1px solid #48423F;
    border-style: none solid solid;
    border-width: 0 1px 1px;
    font-weight: normal;
    left: -999em;
    margin-top: 1px;
    position: absolute;
    text-align: left;
    width: 496px;
}
/* --------- Within Div Styles --------- */
#mega li:hover div {
    left: -1px;
    top: auto;
}
#mega li.dif:hover div {
    left: -407px;
    top: 72px;
}
#mega li.mmore:hover > a {
    color: #FFFFFF; text-shadow: 1px 1px 0 #404747; /* Ensures hover on MORE remains */
}
#mega div h2 {
    background: none repeat scroll 0 0 #999999;
    clear: both;
    float: left;
    font-size: 1em;
    margin: 10px 0 5px;
    padding: 0 10px;
    position: relative;
    width: 300px;
}
#mega div moretopbar {
    clear: both;
    float: left;
    position: relative;
margin-left:1px;
margin-right:1px;
    width: 495px;
    height: 74px;
    background-image: url(images/morebgwide.png);
    background-size:495px 74px;
    background-repeat:no-repeat;
}
#mega div p {
    float: left;
    padding-left: 10px;
    position: relative;
    width: 106px;
}
#mega div p a {
    clear: left;
    float: left;
    line-height: 1.4;
    text-decoration: underline;
    width: 100%;
}
#mega div a:hover, #mega div a:focus, #mega div a:active {
    text-decoration: none;
}
#mega div morecontainer {
    width: 495px;
}
#mega div moreleftbar {
    width: 70%;
}

#mega moreleftbar a { /* I want to style the list here - clean slate*/
    margin-left: 0;
    padding-left: 0;
    list-style-type: none;
    font-family: Arial, Helvetica, sans-serif;
    color: #cc6600;
}

虽然,我会建议俯瞰小提琴,以便可视化地显示该问题: http://jsfiddle.net/XHard/1/

Although, I would advice overlooking the fiddle for a visual presentation of the issue: http://jsfiddle.net/XHard/1/

必须有一种方法在该下拉菜单中创建一个新的干净列表。你能弄清楚怎么样?如果你会回答,请详细说明我的编码知识是有限的 - 理想情况下是更新的小提琴。

There must be a way to make a new clean list in that drop down menu. Can you figure out how? If you will answer, please be detailed as my coding knowledge is limited - ideally with an updated fiddle.

推荐答案

看看firebugs输出的样式,你有< ul> 标签。 CSS规则特定于 #mega 中的< ul> 标签。

Ok so just had a look at firebugs output on the styling of the <ul> tag you have. And the CSS rules are specific to the <ul> tags within #mega.

所以我添加了这个CSS,它定位到你想要的样式,并重新设置一些规则:

So I added this CSS that targets the UL you want to style and reset a few rules:

ul#mega moreleftbar ul,
ul#mega moreleftbar ul li,
ul#mega moreleftbar ul li a,
ul#mega moreleftbar ul li a:hover
{
    padding:0;
    border:0;
    margin:0;
    color:#000000;
    font-size:inherit;
    font-weight:normal;
    background:none;
}

JSfiddle示例

请注意您的原始规则来设计< li>

Notice your original rule for styling the <li>

ul#mega li

这将被我上面应用的目标规则所覆盖。

This will be overwritten by the targetted rules I've applied above.

通过更具体的规则,它们覆盖较少的具体样式(除非一个样式具有!重要的标记)。

By being more specific with the rules, they overwrite less specific styles (unless a style has an !important tagged to it).

.manimation:hover{
    background:#43cf61 !important;
}

上面的规则将阻止你能够应用任何进一步的背景 - 颜色更改为规则涵盖的任何元素。 !重要不是一件好事,除非是绝对必要的。

The above rule for example will stop you being able to apply any further background-color changes to any elements that are covered by the rule. !important is not a good thing to use unless it is absolutely necessary.

这篇关于如何在菜单中创建列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆