如何将不同的风格应用于<ul> <li>和<a> tags in different menu

时间:2016-08-06 14:11:38

标签: html css html5

I want to apply style to top menu <ul>,<li> and <a> tags and different style to body menu <ul>,<li> and <a> tags .

how it is possible.

in short i want different style for ul li and a tags for top menu and different style for ui li and a tags for body menu code for top menu

enter image description here

1 个答案:

答案 0 :(得分:1)

您需要为菜单/项目分配类或ID以区分它们,然后在CSS中设置类/ ID的样式。示例HTML:

<ul id="top-menu">
    <li>
        <a>Item 1</a>
    </li>
    <li>
        <a>Item 2</a>
    </li>
</ul>
<ul class="body-menu">
    <li>
        <a>Item 1</a>
    </li>
    <li>
        <a>Item 2</a>
    </li>
</ul>

CSS:

ul#top-menu {
    STYLES
}
#top-menu > li {
    STYLES
}
#top-menu > li > a {
    STYLES
}
ul.body-menu {
    STYLES
}
ul.body-menu > li {
    STYLES
}
ul.body-menu > li > a {
    STYLES
}