- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between "." and "#" selector in CSS
'.' selector
'.' selector is a class level selector. The dot operator is used to create a style class which can then be applied on multiple html elements.
'#' selector
'#' selector is an element level selector. Hash operator is used to applying style on a particular element whose id is the same as used in '#' selector
Example
Following the example, shows usage of '.' as well as '#' selector on three div elements.
<!DOCTYPE html> <html> <head> <title>Selector Example>/title> <style> .blackBorder { border: 2px solid black; } #redDiv { border: 2px solid red; } </style> </head> <body> <div> No Border Box </div> <div class="blackBorder"> Black Border Box </div> <div id="redDiv"> Red Border Box </div> <div> No Border Box </div> <div class="blackBorder"> Black Border Box </div> </body> </html>
- Related Articles
- What is the primary difference between the XPath and CSS selector in Selenium?
- What is the difference between jQuery(selector) and $(selector)?
- Difference between :focus and :active selector in HTML
- Understanding CSS Selector and Declarations
- Role of CSS :not (selector) Selector
- Universal Selector in CSS
- Difference Between HTML and CSS
- CSS Child Selector
- CSS Descendant Selector
- Element Type Selector in CSS
- Difference Between CSS Display and Visibility
- Difference between CSS Grid and Bootstrap
- Difference between resetting and normalizing CSS?
- Role of CSS :in-range Selector
- Difference Between Pseudo-Class and Pseudo-Element in CSS

Advertisements