Why can't I target the links in this class?

2019-06-06 02:06发布

问题:

I have this class:

.search-modal-navigation-link {
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
    color: #FFF;
    height: 32px;
    font-size: 12px;
    text-align: center;
    float: left;
    margin-right: 22px;
}

And I tried targeting all links in this class so I did this:

a.search-modal-navigation-link:link {
    text-decoration: underline; 
    color: red;
}

and I get nothing, why is this? Thank you :))!

Edit: My Html

 <div class="search-modal-navigation-tab">
    <div class="search-modal-navigation-link"><a href="#">
    <img src="img/icons/01-passive.png" width="20" height="21" border="0" /><BR />
    All Events</a></div>
    <div class="search-modal-navigation-link">
    <img src="img/icons/01-passive.png" width="20" height="21" /><BR />
    All Events</div>

  </div>

回答1:

Your selector isn't looking for links in an element with that class, it's looking for links with that class. You need to change it to this:

.search-modal-navigation-link a:link {
    text-decoration: underline; 
    color: red;
}


回答2:

How about

.search-modal-navigation-link a {
    text-decoration: underline; 
    color: red;
}