css - Which selector will apply for HTML tag -


this question has answer here:

<style>      .divnav      {         font-size:25px;       }       #divnav      {         font-size:25px;       } </style>  <div class="divnav" id="divnav"> 

both id , class have same style.

which apply? , reason?

it apply id style. because id have high specificity .

check:

#divnav         {          font-size:25px;          }  .divnav         {          font-size:15px;          }        
<div class="divnav" id="divnav">test</div>

and:

.divnav         {          font-size:15px;          }          #divnav         {          font-size:25px;          }
<div class="divnav" id="divnav">test</div>


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -