HabibS
HabibS

Reputation: 382

css how to only make bold fonts for first <ul> set

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.

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>

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

Upvotes: 2

Views: 10564

Answers (4)

Blender
Blender

Reputation: 298206

You'll have to use the child selector and make the top-level <ul> unique by giving it some class:

ul.top-level > li > a {
   font-weight: bold;
}​

Demo: http://jsfiddle.net/kJJw9/

Upvotes: 1

Gopikrishna
Gopikrishna

Reputation: 857

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

Upvotes: 0

Alexandre Lavoie
Alexandre Lavoie

Reputation: 8771

It will probably do it...

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

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

Upvotes: 1

Michael
Michael

Reputation: 20049

Use the first child selector: >

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

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;
}

Upvotes: 5

Related Questions