1.

Draw a circle using CSS?

Answer»

In CSS, ID is suggested to be unique for an element whereas the class name is can be the same for many elements. As the ID is unique for the element, ID has higher priority than class in CSS. Consider the below example for better UNDERSTANDING.

<!DOCTYPE html> <html>   <head>     <style>        #rcorners {         border-radius: 50%;         background: #FF0000;         border: 3px solid black;         PADDING: 20px;         WIDTH: 200px;         HEIGHT: 200px;       }       .corners-div {         border-radius: 50%;         background: #73AD21;         padding: 1px;         width: 20px;         height: 20px;       }     </style>   </head>   <body>     <div id="rcorners" class="corners-div"></div>   </body> </html>

OUTPUT:

For the above example, we still see the background color like red with the black border as output even after trying to override the background color as green without a border using the class selector below. This clearly answers our question that ID has a higher priority than class.



Discussion

No Comment Found