css如何只为第一个使用粗体字体< ul>组 [英] css how to only make bold fonts for first <ul> set

查看:173
本文介绍了css如何只为第一个使用粗体字体< ul>组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在里面有2个或更多< UL> 套件,并且只想让第一个UL < a> 设置为粗体。
事实上,这是一个带有多个子菜单的菜单,我只想让父级链接加粗。

I have 2 or more <UL> sets inside, and wants to only make first UL <a> set to bold. in fact, this is a menu with multiple sub menus, and I only want to make parent links bold.

我知道这可以通过添加一些更多的ID或类,但这不是一个选项,只是想尝试css方法。

I know it can be done by adding some more ID's or classes, but this is not an option, and just want to try css method only.

<ul class="menu">
    <li class="collapsed first">
        <a title="Mechanical products" href="1">Mechanical Products</a>
    </li>
  <li class="collapsed">
    <a title="Chemicals" href="2">Chemicals</a>
  </li>
  <li class="expanded active-trail">
    <a title="Instrumentation" href="3">Instrumentation</a>
    <ul class="menu">
        <li class="leaf first">
            <a title="Control valves FISHER" href="4">Control Valves</a>
        </li>
      <li class="expanded active-trail">
        <a class="active" title="Corrosion Monitoring System" href="5">Corrosion Monitoring</a>
        <ul class="menu">
            <li class="leaf first">
                <a title="Access Fitting Assemblies" href="6">Fitting Assemblies</a>
            </li>
          <li class="leaf last">
            <a title="Coupon Holders, Coupons &amp; Probes" href="7">Holders,Coupons</a>
          </li>
        </ul>
      </li>
    </ul>
  </li>
    <li class="collapsed">
        <a title="Mechanical products2" href="8">Mechanical Products2</a>
    </li>
</ul>

,只有Mechanical Products,Chemicals,Instrumentation和Mechanical

as of this example, only "Mechanical Products", "Chemicals", "Instrumentation" and "Mechanical Products2" should get bold.

推荐答案

使用第一个子选择器:>

Use the first child selector: >

.menu > li {
    font-weight: bold;
}

不是因为如果你需要支持IE6,你必须这样做手动,因为IE6不支持> 选择器:

Not that if you need to support IE6, you'll have to do it manually, as IE6 doesn't support the > selector:

.menu li a {
    font-weight: bold;
}
.menu li ul li a {
    font-weight: normal;
}

这篇关于css如何只为第一个使用粗体字体&lt; ul&gt;组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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