sky
sky

Reputation: 75

How to style different CSS in an anchor tag?

I'm still new with all of this. I've apply CSS in anchor tag for navigation menu. It worked perfectly.

<style>
.navbar {
overflow: hidden;
background-color:  rgb(143, 0, 50);
font-family: "Arial Black", Gadget, sans-serif; 
}

.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
 }
.navbar a:hover:not(.active) {
background-color: #FCD078;
}
 .navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}


.navbar a:hover:not(.active) {
background-color: #FCD078;
 }

.active {
background-color:rgb(182, 58, 78);
}
.dropdown {
 float: left;
 overflow: hidden;
 }

.dropdown .dropbtn {
font-size: 16px;    
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}

.navbar a:hover, .dropdown:hover .dropbtn {
background-color: #FFA500;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}

.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}

.dropdown-content a:hover {
background-color: #FFA500;
}

.dropdown:hover .dropdown-content {
display: block;
}
</style>

But as soon as I try to create a list under the menu where there's anchor tag in it, the list follow the navigation menu's CSS element. Even though, I've created a class for the list.

<ul>
<li class="form"><a href="#" >Form 1</li>
<li class="form"><a href="#" >Form 2</li>
<ul>

This is the class for the list

 ul li.form::before {
 content: "\2022";
 color: red;
 font-weight: bold;
 display: inline-block; 
 width: 1em;
 margin-left: -70em; 
 }

Is there a way I can style different CSS in anchor tag? CSS that specific for a particular anchor tag. For example, navigation menu and the list. Thank you for your time

Upvotes: 0

Views: 3073

Answers (2)

Ravikumar C Bhambhani
Ravikumar C Bhambhani

Reputation: 101

Yes, you can apply different css for different anchor tag or specific to a particular anchor tag as follows:

provide ID to anchor tags and create css for the same

    <ul>
    <li class="form"><a href="#" id="f1"> form1 </a></li>
    <li class="form"><a href="#" id="f2"> form2 </a></li>
    <li class="form"><a href="#" id="f3"> form3 </a></li>
    </ul>

and the css for different anchor tag

    #f1{
    color:#00FFFF;
    }
    #f2{
    color:#B22222;
    }
    #f3{
    color:#228B22;
    }

Hope you get the work done.

Upvotes: 2

Sheedo
Sheedo

Reputation: 554

Make sure to close your anchor tags:

<ul>
<li class="form"><a href="#" >Form 1</a></li>
<li class="form"><a href="#" >Form 2</a></li>
<ul>

Upvotes: 1

Related Questions