SlideShare a Scribd company logo
CSS Classes
What is a CSS Class? A CSS class provides us with a tool to create custom styles for elements on our web pages.  Using classes can save us from typing the same formatting code for numerous elements.  Classes enable us to make wide-scale styling changes very quickly. In our earlier examples of using CSS, we applied the same formatting to all instances of a particular element.  A CSS class allows us to define different styles for the same element type .  For example, we can make one paragraph appear in green text and another paragraph show in red text.
Syntax and Use of CSS Classes: Class definitions are placed along with all the other CSS inside the <head> section of the document.  <head> <style type=&quot;text/css&quot;> .center { text-align:center; } </style> </head> <p>Paragraph 1</p> <p  class=&quot;center&quot; >Paragraph 2</p> A CSS class is defined with a period, followed by the name of the class.  Paragraph 1 Paragraph 2 By adding the  class=&quot;center&quot;  to this paragraph element, we are telling the browser to apply all formatting defined for that class to this particular paragraph.
Syntax and Use of CSS Classes: As before, multiple styles can be defined in a single statement.  Remember the semicolon at the end of each line. <head> <style type=&quot;text/css&quot;> .special { text-align:center; color:green; font-style:italic; } </style> </head> <p  class=&quot;special&quot; >Paragraph</p> Paragraph
Syntax and Use of CSS Classes: CSS classes can even be combined.  The element will reflect the formatting definitions from all the classes being applied. <head> <style type=&quot;text/css&quot;> .center { text-align:center; } .green { color:green; } .italic { font-style:italic; } </style> </head> <p  class=&quot;center green italic&quot; >Paragraph</p> Paragraph
Syntax and Use of CSS Classes: Generic classes like these can be applied to any element we choose. <head> <style type=&quot;text/css&quot;> .green { color:green; } </style> </head> <h1  class=&quot;green&quot; >Heading</h1> <p  class=&quot;green&quot; >Paragraph</p> <ul> <li>List Item 1</li> <li  class=&quot;green&quot; >List Item 2</li> </ul> Heading Paragraph List Item 1 List Item 2
Syntax and Use of CSS Classes: You can also specify that only particular elements be affected by a class. <head> <style type=&quot;text/css&quot;> p.green { color:green; } </style> </head> <h1  class=&quot;green&quot; >Heading</h1> <p  class=&quot;green&quot; >Paragraph</p> <ul> <li>List Item 1</li> <li  class=&quot;green&quot; >List Item 2</li> </ul> Heading Paragraph List Item 1 List Item 2 In this example, we have defined the .green class to apply only to the paragraph element. If we try to apply the .green class to other elements, it will have no effect; the browser will simply ignore the class definition.
The <span> element: The <span> tag allows us to apply class styling to a specific section within an element. <head> <style type=&quot;text/css&quot;> .green { color:green; } </style> </head> <p>This is a  <span class=&quot;green&quot;>  typical </span>  paragraph</p> This is a  typical  paragraph. Note that the <span> tag does nothing on its own.  Only when we associate it with a class does it make a change to how the page displays.
Naming CSS Classes: Give some thought to how you name your CSS classes. By using class names that describe how the element will look (.green, .center), we can make things confusing in the future.  What if we later change our green text to be red?  We would have the .green class display in red! A much better approach is to use class names that describe the  meaning  of the content, not how it will look: Problematic names .green .underline .center .bigletters Better names .slogan .booktitle .caption .headline

More Related Content

PPTX
Webdesign
PPTX
Css presentation
PPTX
Css intro
PPT
Working with External CSS
PPT
Page Layout 2010
PPTX
HTML to FTP
PPT
Basic html
Webdesign
Css presentation
Css intro
Working with External CSS
Page Layout 2010
HTML to FTP
Basic html

What's hot (16)

PPT
Cheat codes
PPT
Week3 css
PPTX
PPTX
Std 10 Chapter 2 Head and Body Sections in HTML (Part 2- Body section)
PPTX
Html Power Point 5
PPTX
Web Design Assignment 1
PPTX
How an html file is structured
PPT
ARTDM 171 Week 4: Tags
PPTX
Css Basics
PPT
3.2 introduction to css
PPT
Html2 Intro
PPT
Advanced Cascading Style Sheets
PDF
Introduction to css
PPT
10x10
Cheat codes
Week3 css
Std 10 Chapter 2 Head and Body Sections in HTML (Part 2- Body section)
Html Power Point 5
Web Design Assignment 1
How an html file is structured
ARTDM 171 Week 4: Tags
Css Basics
3.2 introduction to css
Html2 Intro
Advanced Cascading Style Sheets
Introduction to css
10x10
Ad

Viewers also liked (20)

PPTX
Mūžizglītības programmas comenius apkašprogrammas
PPTX
Solar energy
PPTX
Špoģi-Syke
PPTX
Ajusal
PPT
1.3 creating links
PPTX
Another world by Anna Sintija
PPT
Social media and PR
PPT
Landmark
PPTX
Komonvelt portoriko
PPS
Power a
PPTX
Enviornmental injustice
PPTX
A Dress made of recycled materials
PPTX
Shpogy secondary school
PPS
LETRA A
PPTX
Handball
PPTX
Fashion than and_now
PDF
Scala de beck
PPT
Questionaire all-students-2011
PPTX
Savannah's restoration site powerpoint
DOC
Fstpt 9 agungkartika 10hal-revisi
Mūžizglītības programmas comenius apkašprogrammas
Solar energy
Špoģi-Syke
Ajusal
1.3 creating links
Another world by Anna Sintija
Social media and PR
Landmark
Komonvelt portoriko
Power a
Enviornmental injustice
A Dress made of recycled materials
Shpogy secondary school
LETRA A
Handball
Fashion than and_now
Scala de beck
Questionaire all-students-2011
Savannah's restoration site powerpoint
Fstpt 9 agungkartika 10hal-revisi
Ad

Similar to 4.2 css classes (20)

ODP
ODP
PPT
Basics Of Css And Some Common Mistakes
PPT
PPT
Basic css
PPTX
Embrace the Mullet: CSS is the 'Party in the Back' (a CSS How-to)
PPT
CSS Part I
PPT
How Cascading Style Sheets (CSS) Works
PPT
PPT
Css Ppt
ODP
Cascading Style Sheets - Part 01
PPT
Introduction to Cascading Style Sheets
ODP
Css.prabu
PPTX
LIS3353 SP12 Week 13
PPT
cascading style sheet ppt
PPT
Introduction to Cascading Style Sheets (CSS)
PPT
DOC
Css 1
 
Basics Of Css And Some Common Mistakes
Basic css
Embrace the Mullet: CSS is the 'Party in the Back' (a CSS How-to)
CSS Part I
How Cascading Style Sheets (CSS) Works
Css Ppt
Cascading Style Sheets - Part 01
Introduction to Cascading Style Sheets
Css.prabu
LIS3353 SP12 Week 13
cascading style sheet ppt
Introduction to Cascading Style Sheets (CSS)
Css 1
 

More from Bulldogs83 (17)

PPT
7.2 external style sheets
PPT
7.1 xhtml validation
PPT
6.2 css link styling
PPT
6.1 special characters
PPT
5.2 nesting and floating elements
PPT
5.1 css box model
PPT
4.3 table styling
PPT
4.1 advanced tables
PPT
3.2 introduction to css
PPT
3.1 xhtml tables
PPT
2.1 adding images
PPT
1.4 adding comments copy (2)
PPT
1.4 adding comments copy (2)
PPT
1.3 creating links
PPT
1.2 elements and attributes copy (3)
PPT
1.2 elements and attributes copy (3)
PPT
1.1 xhtml basics
7.2 external style sheets
7.1 xhtml validation
6.2 css link styling
6.1 special characters
5.2 nesting and floating elements
5.1 css box model
4.3 table styling
4.1 advanced tables
3.2 introduction to css
3.1 xhtml tables
2.1 adding images
1.4 adding comments copy (2)
1.4 adding comments copy (2)
1.3 creating links
1.2 elements and attributes copy (3)
1.2 elements and attributes copy (3)
1.1 xhtml basics

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Institutional Correction lecture only . . .
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Cell Structure & Organelles in detailed.
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Classroom Observation Tools for Teachers
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Lesson notes of climatology university.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
Institutional Correction lecture only . . .
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Computing-Curriculum for Schools in Ghana
Cell Structure & Organelles in detailed.
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
TR - Agricultural Crops Production NC III.pdf
Complications of Minimal Access Surgery at WLH
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Classroom Observation Tools for Teachers
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Lesson notes of climatology university.
2.FourierTransform-ShortQuestionswithAnswers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape

4.2 css classes

  • 2. What is a CSS Class? A CSS class provides us with a tool to create custom styles for elements on our web pages. Using classes can save us from typing the same formatting code for numerous elements. Classes enable us to make wide-scale styling changes very quickly. In our earlier examples of using CSS, we applied the same formatting to all instances of a particular element. A CSS class allows us to define different styles for the same element type . For example, we can make one paragraph appear in green text and another paragraph show in red text.
  • 3. Syntax and Use of CSS Classes: Class definitions are placed along with all the other CSS inside the <head> section of the document. <head> <style type=&quot;text/css&quot;> .center { text-align:center; } </style> </head> <p>Paragraph 1</p> <p class=&quot;center&quot; >Paragraph 2</p> A CSS class is defined with a period, followed by the name of the class. Paragraph 1 Paragraph 2 By adding the class=&quot;center&quot; to this paragraph element, we are telling the browser to apply all formatting defined for that class to this particular paragraph.
  • 4. Syntax and Use of CSS Classes: As before, multiple styles can be defined in a single statement. Remember the semicolon at the end of each line. <head> <style type=&quot;text/css&quot;> .special { text-align:center; color:green; font-style:italic; } </style> </head> <p class=&quot;special&quot; >Paragraph</p> Paragraph
  • 5. Syntax and Use of CSS Classes: CSS classes can even be combined. The element will reflect the formatting definitions from all the classes being applied. <head> <style type=&quot;text/css&quot;> .center { text-align:center; } .green { color:green; } .italic { font-style:italic; } </style> </head> <p class=&quot;center green italic&quot; >Paragraph</p> Paragraph
  • 6. Syntax and Use of CSS Classes: Generic classes like these can be applied to any element we choose. <head> <style type=&quot;text/css&quot;> .green { color:green; } </style> </head> <h1 class=&quot;green&quot; >Heading</h1> <p class=&quot;green&quot; >Paragraph</p> <ul> <li>List Item 1</li> <li class=&quot;green&quot; >List Item 2</li> </ul> Heading Paragraph List Item 1 List Item 2
  • 7. Syntax and Use of CSS Classes: You can also specify that only particular elements be affected by a class. <head> <style type=&quot;text/css&quot;> p.green { color:green; } </style> </head> <h1 class=&quot;green&quot; >Heading</h1> <p class=&quot;green&quot; >Paragraph</p> <ul> <li>List Item 1</li> <li class=&quot;green&quot; >List Item 2</li> </ul> Heading Paragraph List Item 1 List Item 2 In this example, we have defined the .green class to apply only to the paragraph element. If we try to apply the .green class to other elements, it will have no effect; the browser will simply ignore the class definition.
  • 8. The <span> element: The <span> tag allows us to apply class styling to a specific section within an element. <head> <style type=&quot;text/css&quot;> .green { color:green; } </style> </head> <p>This is a <span class=&quot;green&quot;> typical </span> paragraph</p> This is a typical paragraph. Note that the <span> tag does nothing on its own. Only when we associate it with a class does it make a change to how the page displays.
  • 9. Naming CSS Classes: Give some thought to how you name your CSS classes. By using class names that describe how the element will look (.green, .center), we can make things confusing in the future. What if we later change our green text to be red? We would have the .green class display in red! A much better approach is to use class names that describe the meaning of the content, not how it will look: Problematic names .green .underline .center .bigletters Better names .slogan .booktitle .caption .headline