html - How do I set the background color for links? -


i've been trying figure out on how set current page i'm @ different background color other links, no avail.

html

<div id="navigation">     <ul>         <li><a href="<?php echo base_url() ?>index.php/home">home</a></li>         <li><a href="<?php echo base_url() ?>index.php/portfolio">portfolio</a></li>         <li><a href="<?php echo base_url() ?>index.php/about">about</a></li>         <li><a href="<?php echo base_url() ?>index.php/gallery">gallery</a></li>         <li><a href="<?php echo base_url() ?>index.php/blog">blog</a></li>     </ul> </div> 

what want set current active link black, , other 4 links grey. way if visit portfolio, example, link black , rest grey. how this?

thankfully, there no javascript involved. html , css work fine task. first off, let's create html. know page on, going add class current page's link. so, example, if on /index.php/home our markup might similar this.

<div id="navigation">     <ul>         <li><a class="current" href="<?php echo base_url() ?>index.php/home">home</a></li>         <li><a href="<?php echo base_url() ?>index.php/portfolio">portfolio</a></li>         <li><a href="<?php echo base_url() ?>index.php/about">about</a></li>         <li><a href="<?php echo base_url() ?>index.php/gallery">gallery</a></li>         <li><a href="<?php echo base_url() ?>index.php/blog">blog</a></li>     </ul> </div> 

now, before color current link going color rest of links. can select rest of links via css so.

#navigation { } 

the following css select <a> elements children of navigation element. need set background color. css property setting background color background-color: xxx. xxx either hex code, rgb value, or name of color. following have links grey.

#navigation {     background-color: #333; /* or whatever grey want. */ } 

this set every link color grey. now, need set current link color black.

if noticed, added class="current" current link, home link in case. next need create appropriate styling this. our css declaration similar this.

#navigation .current { } 

the above declaration applies elements class current child of element navigation. , set background color so.

#navigation .current {     background-color: #000; } 

so, our final css so.

#navigation {     background-color: #333; }  #navigation .current {     background-color: #000; } 

note order important! if put second declaration first, overridden the, more general, link declaration.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -