Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

CSS dropdown hover issue

Featured Replies

Hi,

I nearly always use PHP includes for my navigational links to aid changes and maintenance to the site, and so the correct menu item is easily identifiable as the 'current' item. However, when I'm trying to apply that principle to this page (http://www.azuremarketing.com/clients/ocsl/web/safety-management.php), the whole of the dropdown menu appears to be 'selected'. I'm sure there's an easy work around, but I've just looked at it too much. I'd be really grateful if someone had any ideas about how I can rectify this (the 'capabilities' category is correct to look 'current', but the others in the dropdown box should be white).

Any tips would be appreciated.

Many thanks

Vicky

Hi Vicky,

 

I think it is because you are styling the <li> and not the <a>.

 

This is your current code:

 

#navigation li.active a,
#navigation li a:hover{color:#fdc21c;}

<li  class="active"><a href="#">Capabilities</a>
<ul>
  <li><a href="#">Safety Management</a></li>

  <li><a href="#">Risk Management</a></li>
  <li><a href="#">Project Management</a></li>
  <li><a href="#">Business Development</a></li>
  <li><a href="#">Bid Support</a></li>
</ul>
</li>

 

Change it to this:

 

#navigation li a.active,
#navigation li a:hover{color:#fdc21c;}

<li><a href="#" class="active">Capabilities</a>
<ul>
  <li><a href="#">Safety Management</a></li>

  <li><a href="#">Risk Management</a></li>
  <li><a href="#">Project Management</a></li>
  <li><a href="#">Business Development</a></li>
  <li><a href="#">Bid Support</a></li>
</ul>
</li>

 

-Ben

  • Author

Hi Ben

 

Thanks so much for looking at that for me. You were right, that is why it wasn't working properly. However, having now switched it over to styling the <a> rather than the <li> means that the 'active' colour no longer works, ie: this part of the code:

 

<li <?php if ($thisPage=="Capabilities")

echo " class=\"active\""; ?>><a href="#">Capabilities</a>

<ul>

<li><a href="#">Safety Management</a></li>

<li><a href="#">Risk Management</a></li>

<li><a href="#">Project Management</a></li>

<li><a href="#">Business Development</a></li>

<li><a href="#">Bid Support</a></li>

</ul>

</li>

 

I'm just looking at a fix now so I'll let you know if I work it out!

 

Many thanks again

 

Vicky

Hi Ben

 

Thanks so much for looking at that for me. You were right, that is why it wasn't working properly. However, having now switched it over to styling the <a> rather than the <li> means that the 'active' colour no longer works, ie: this part of the code:

 

<li <?php if ($thisPage=="Capabilities")

echo " class=\"active\""; ?>><a href="#">Capabilities</a>

<ul>

<li><a href="#">Safety Management</a></li>

<li><a href="#">Risk Management</a></li>

<li><a href="#">Project Management</a></li>

<li><a href="#">Business Development</a></li>

<li><a href="#">Bid Support</a></li>

</ul>

</li>

 

I'm just looking at a fix now so I'll let you know if I work it out!

 

Many thanks again

 

Vicky

Hi Vicky,

 

You should just be able to swap the php code into the <a> tag:

 

<li><a href="#" <?php if ($thisPage=="Capabilities")
echo " class=\"active\""; ?>>Capabilities</a>
<ul>
  <li><a href="#">Safety Management</a></li>
  <li><a href="#">Risk Management</a></li>
  <li><a href="#">Project Management</a></li>
  <li><a href="#">Business Development</a></li>
  <li><a href="#">Bid Support</a></li>
</ul>
</li>

 

- Ben

  • Author

So logical when you put it that way, but it would have taken me ages to come up with that! Thank you so much - that now works perfectly - you're a genius.

I really appreciate your help.

Many thanks

Vicky

So logical when you put it that way, but it would have taken me ages to come up with that! Thank you so much - that now works perfectly - you're a genius.

I really appreciate your help.

Many thanks

Vicky

No problem :)

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.