SlideShare a Scribd company logo
CSS Selectors: element,
class, id
Danilo D’Auria
What is CSS?
CSS stand for Cascading Style Sheets, it is a style sheet language used to help
design web pages. Through HTML we take care of the page’s structure while with
CSS we focus on make content looks right.
HTML does this With CSS it becomes this
CSS Syntax
Source: http://www.w3schools.com/css/css_syntax.asp
In CSS we can add style to HTML tags. It can be done by:
• Using a declarati0n block for that tag. It will be applied everywhere in your page;
• Using inline style
• Using class attribute
• Using id attribute
In each case the CSS Syntax will be like the one show below, where we can have many
declarations (property and value) for the same block
Declaration Block on HTML tag
When we want to apply the same set of declaration to specific tags, we can use the
following structure.
e.g.
Declaration Block Description
h2 {color:black;} It applies to all h2 headings the text
color black
h1,h2,h3,h4,h5,h6 {color:white; font-
weight:bold;}
It applies to all headings from h1 to h6
the text white and bold
img {border:0px;margin:0px} It removes borders and margins to all
the images
p {font-family: Arial;} It applies to all the paragraph the Arial
font.
Inline style 1/2
Inline style it’s useful when you want to apply a specific style to only one element.
In which case you could consider to apply the style directly in the tag element.
Please note that it’s best
practice to keep CSS style
in a separate stylesheet.
<h2 style=“font-size:24px; color: red;”>Heading 2<h2>
Using the attribute style, we are applying a bigger font-
size to the h2 and assign the text color red . So in the page
it would look like this:
Heading 2
Inline style 2/2
Example
Write the text Hello World in a div with width 200px and height 200px .
The div will have background red and the text in the div must be yellow.
<div style=“width: 200px; height: 200px; background: red; color: yellow;”>
Hello World
</div>
Output
Class attribute
Using the class attribute we can define a common style that we want to give to all the tags having that attribute.
Example
let’s say that we want to assign text c0lor blue to all the <li> tags in a specific list. So what we need to do is:
<style>
.list-item{color:blue;}
</style>
…
<ul>
<li class=“list-item”>bag</li>
<li class=“list-item”>better</li>
<li class=“list-item”>bird</li>
<li class=“list-item”>boat</li>
<li class=“list-item”>butter</li>
</ul>
Id attribute
We can use the id attribute when we want to give assign a specific style to an item
in the page. Each specific id can be used only once in each page. If you need to use
the same style to multiple items in a page then use the class attribute.
Example
Apply font weight bold, white text, and border brown to a div containing the text:
“I like CSS”
<style>
#myDiv {
font-weight:bold;
color:#ffffff;
border: 2px solid brown;
}
</style>
<div id=“myDiv”>
I live CSS
</div>
Conclusion
There are many ways that we can use CSS and apply it to our code. However the
best way to do it is by using the id and class attributes. Remember to use class
when you want to apply the same style to multiple items in your code, otherwise
for specific/custom style to an item use the id attribute

More Related Content

What's hot

CSS Basics - Stylesheets and Color
CSS Basics - Stylesheets and ColorCSS Basics - Stylesheets and Color
CSS Basics - Stylesheets and Color
Kelly Kellum
 
Css
CssCss
Styling of css
Styling of cssStyling of css
Styling of css
JayjZens
 
TM 1st quarter - 4th meeting
TM   1st quarter - 4th meetingTM   1st quarter - 4th meeting
TM 1st quarter - 4th meeting
Esmeraldo Jr Guimbarda
 
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntax
priyadharshini murugan
 
Css ms megha
Css ms meghaCss ms megha
Css ms megha
Megha Gupta
 
CSS LAY OUT
CSS LAY OUTCSS LAY OUT
CSS LAY OUTkylleses
 
Share google documents with others
Share google documents with othersShare google documents with others
Share google documents with others
Paul Enrique Casas
 
Ppt of web designing
Ppt of web designingPpt of web designing
Ppt of web designing
prab5
 
FFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSSFFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSS
Toni Kolev
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
WordPress Memphis
 
Completing Your Design with WordPress
Completing Your Design with WordPressCompleting Your Design with WordPress
Completing Your Design with WordPressChelsea Otakan
 
Introductory css and j query
Introductory css and j queryIntroductory css and j query
Introduction of css
Introduction of cssIntroduction of css
Introduction of css
Dinesh Kumar
 
CSS-3 Course Slide
CSS-3 Course SlideCSS-3 Course Slide
CSS-3 Course Slide
BoneyGawande
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
vijayta
 

What's hot (20)

CSS Basics - Stylesheets and Color
CSS Basics - Stylesheets and ColorCSS Basics - Stylesheets and Color
CSS Basics - Stylesheets and Color
 
Css
CssCss
Css
 
Styling of css
Styling of cssStyling of css
Styling of css
 
TM 1st quarter - 4th meeting
TM   1st quarter - 4th meetingTM   1st quarter - 4th meeting
TM 1st quarter - 4th meeting
 
Introduction to css & its attributes with syntax
Introduction to css & its attributes with syntaxIntroduction to css & its attributes with syntax
Introduction to css & its attributes with syntax
 
Css ms megha
Css ms meghaCss ms megha
Css ms megha
 
Cascstylesheets
CascstylesheetsCascstylesheets
Cascstylesheets
 
Css
CssCss
Css
 
CSS LAY OUT
CSS LAY OUTCSS LAY OUT
CSS LAY OUT
 
Html and css
Html and cssHtml and css
Html and css
 
Share google documents with others
Share google documents with othersShare google documents with others
Share google documents with others
 
Ppt of web designing
Ppt of web designingPpt of web designing
Ppt of web designing
 
Lecture2
Lecture2Lecture2
Lecture2
 
FFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSSFFW Gabrovo PMG - CSS
FFW Gabrovo PMG - CSS
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Completing Your Design with WordPress
Completing Your Design with WordPressCompleting Your Design with WordPress
Completing Your Design with WordPress
 
Introductory css and j query
Introductory css and j queryIntroductory css and j query
Introductory css and j query
 
Introduction of css
Introduction of cssIntroduction of css
Introduction of css
 
CSS-3 Course Slide
CSS-3 Course SlideCSS-3 Course Slide
CSS-3 Course Slide
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
 

Similar to CSS Selectors: element, class, id

IP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).pptIP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).ppt
kassahungebrie
 
html-css
html-csshtml-css
Lecture 3CSS part 1.pptx
Lecture 3CSS part 1.pptxLecture 3CSS part 1.pptx
Lecture 3CSS part 1.pptx
GmachImen
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
nikhilsh66131
 
Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8
RohanMistry15
 
CSS - Basics
CSS - BasicsCSS - Basics
CSS - Basics
Shubham_Saurabh
 
Css basics
Css basicsCss basics
Css basics
ASIT
 
Unit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptUnit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.ppt
TusharTikia
 
Workshop 2 Slides.pptx
Workshop 2 Slides.pptxWorkshop 2 Slides.pptx
Workshop 2 Slides.pptx
DaniyalSardar
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideRohan Chandane
 
Css introduction
Css  introductionCss  introduction
Css introduction
vishnu murthy
 
Css
CssCss
Css
CssCss
Css1
Css1Css1
Web topic 15 1 basic css layout
Web topic 15 1  basic css layoutWeb topic 15 1  basic css layout
Web topic 15 1 basic css layoutCK Yang
 
CSS: How To Learn Easily
CSS: How To Learn EasilyCSS: How To Learn Easily
CSS: How To Learn Easily
shabab shihan
 
Css ppt
Css pptCss ppt
Css ppt
Nidhi mishra
 

Similar to CSS Selectors: element, class, id (20)

IP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).pptIP - Lecture 6, 7 Chapter-3 (3).ppt
IP - Lecture 6, 7 Chapter-3 (3).ppt
 
CSS.pdf
CSS.pdfCSS.pdf
CSS.pdf
 
html-css
html-csshtml-css
html-css
 
Lecture 3CSS part 1.pptx
Lecture 3CSS part 1.pptxLecture 3CSS part 1.pptx
Lecture 3CSS part 1.pptx
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8Advanced Web Programming Chapter 8
Advanced Web Programming Chapter 8
 
CSS - Basics
CSS - BasicsCSS - Basics
CSS - Basics
 
Css basics
Css basicsCss basics
Css basics
 
Unit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.pptUnit 2-CSS & Bootstrap.ppt
Unit 2-CSS & Bootstrap.ppt
 
Workshop 2 Slides.pptx
Workshop 2 Slides.pptxWorkshop 2 Slides.pptx
Workshop 2 Slides.pptx
 
TIBCO General Interface - CSS Guide
TIBCO General Interface - CSS GuideTIBCO General Interface - CSS Guide
TIBCO General Interface - CSS Guide
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
Css
CssCss
Css
 
Css
CssCss
Css
 
Css1
Css1Css1
Css1
 
Web topic 15 1 basic css layout
Web topic 15 1  basic css layoutWeb topic 15 1  basic css layout
Web topic 15 1 basic css layout
 
CSS: How To Learn Easily
CSS: How To Learn EasilyCSS: How To Learn Easily
CSS: How To Learn Easily
 
Css
CssCss
Css
 
Css ppt
Css pptCss ppt
Css ppt
 
Css
CssCss
Css
 

Recently uploaded

MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 

Recently uploaded (20)

MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 

CSS Selectors: element, class, id

  • 1. CSS Selectors: element, class, id Danilo D’Auria
  • 2. What is CSS? CSS stand for Cascading Style Sheets, it is a style sheet language used to help design web pages. Through HTML we take care of the page’s structure while with CSS we focus on make content looks right. HTML does this With CSS it becomes this
  • 3. CSS Syntax Source: http://www.w3schools.com/css/css_syntax.asp In CSS we can add style to HTML tags. It can be done by: • Using a declarati0n block for that tag. It will be applied everywhere in your page; • Using inline style • Using class attribute • Using id attribute In each case the CSS Syntax will be like the one show below, where we can have many declarations (property and value) for the same block
  • 4. Declaration Block on HTML tag When we want to apply the same set of declaration to specific tags, we can use the following structure. e.g. Declaration Block Description h2 {color:black;} It applies to all h2 headings the text color black h1,h2,h3,h4,h5,h6 {color:white; font- weight:bold;} It applies to all headings from h1 to h6 the text white and bold img {border:0px;margin:0px} It removes borders and margins to all the images p {font-family: Arial;} It applies to all the paragraph the Arial font.
  • 5. Inline style 1/2 Inline style it’s useful when you want to apply a specific style to only one element. In which case you could consider to apply the style directly in the tag element. Please note that it’s best practice to keep CSS style in a separate stylesheet. <h2 style=“font-size:24px; color: red;”>Heading 2<h2> Using the attribute style, we are applying a bigger font- size to the h2 and assign the text color red . So in the page it would look like this: Heading 2
  • 6. Inline style 2/2 Example Write the text Hello World in a div with width 200px and height 200px . The div will have background red and the text in the div must be yellow. <div style=“width: 200px; height: 200px; background: red; color: yellow;”> Hello World </div> Output
  • 7. Class attribute Using the class attribute we can define a common style that we want to give to all the tags having that attribute. Example let’s say that we want to assign text c0lor blue to all the <li> tags in a specific list. So what we need to do is: <style> .list-item{color:blue;} </style> … <ul> <li class=“list-item”>bag</li> <li class=“list-item”>better</li> <li class=“list-item”>bird</li> <li class=“list-item”>boat</li> <li class=“list-item”>butter</li> </ul>
  • 8. Id attribute We can use the id attribute when we want to give assign a specific style to an item in the page. Each specific id can be used only once in each page. If you need to use the same style to multiple items in a page then use the class attribute. Example Apply font weight bold, white text, and border brown to a div containing the text: “I like CSS” <style> #myDiv { font-weight:bold; color:#ffffff; border: 2px solid brown; } </style> <div id=“myDiv”> I live CSS </div>
  • 9. Conclusion There are many ways that we can use CSS and apply it to our code. However the best way to do it is by using the id and class attributes. Remember to use class when you want to apply the same style to multiple items in your code, otherwise for specific/custom style to an item use the id attribute