如何风格菜单中的列表吗?(How to style a list within a menu?)

2019-09-21 05:44发布

请将鼠标悬停在此菜单中的更多按钮: http://jsfiddle.net/XHard/1/你会看到,有包含单词新的清洁列表清单。 我想要的风格,列表中,但因为它是里面的菜单,它已经具备了造型吧。

我想创建一个新的干净的风格,但无法找到一个方法来做到这一点。 我试图玩弄#mega moreleftbar a ,但原来的菜单列表样式仍然存在。

有没有一种方法,使一个新的干净的造型为菜单内的列表?

这是我的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的一部分:

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/

必须有一种方法,使在下拉菜单中选择一个新的干净的名单。 你能弄清楚如何? 如果你会回答,请详述我的编码知识是有限的 - 最好有一个更新的小提琴。

Answer 1:

好了,所以刚一看firebugs输出上的造型<ul>你有标签。 而CSS规则是特定于<ul>内标签#mega

所以我说这个CSS靶向要的风格和重置一些规则UL:

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>

ul#mega li

这将通过我上面应用了针对性的规则,被覆盖。

通过更具体的规则,它们将覆盖不太具体样式(除非风格有一个!重要标记的话)。

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

例如,上述规则将阻止你能够进一步的背景颜色更改应用到由规则所涵盖的任何元素。 !important是不要用,除非它是绝对必要的一件好事。



文章来源: How to style a list within a menu?