Search
Home
Web Tutorials
Beginner Tutorial
HTML Tutorial
CSS Tutorial
Scripting
Javascript Tutorial
PHP Tutorial
Perl Tutorial
Ajax Tutorial
ASP Tutorial
VBScript Tutorial
Databases
SQL Tutorial
MySQL Tutorial
Miscellaneous
XML Tutorial
Webhost Tutorial
Flash Tutorial
SEO Tutorial
CSS Tutorial
CSS - Introduction
CSS - Selector
CSS - Internal
CSS - External
CSS - Inline
CSS - Class
CSS - Background
CSS - Font
CSS - Text
CSS - Padding
CSS - Margin
CSS - Border
CSS - List
CSS - Pseudo Class &
Mouseover
Advanced Topics
CSS - Cursor
CSS - Properties
CSS - Position
CSS - Layers
CSS - Float
CSS - ID vs Class
CSS - Display
Get Help!
CSS Forum
Contact Us
cssclasses
You may be wondering if it is possible to give an HTML element multiple looks
with CSS. Say for example that sometimes you want the font to be large and white,
while other times you would prefer the font to be small and black. CSS would not be
very useful if it did not allow you to have many different types of formats for a single
HTML tag. Well, you are in luck! CSS allows you to do just that with the use of
classes.
Advertise on Tizag.com
the formatofclasses
Using classes is simple. You just need to add an extension to the typical CSS
code and make sure you specify this extension in your HTML. Let's try this with an
example of making two paragraphs that behave differently. First, we begin with the
CSS code, note the red text.
CSS Code:
HTML Code:
Display:
This is a normal paragraph.
This is a paragraph that uses the p.first CSS code!
This is a paragraph that uses the p.second CSS code!
You can use CSS classes with any HTML element! However, what happens if
we had already defined a value for the default <p> tag, would this cause any
problems for classes of the paragraph tag?
Well, when this happens the CSS class for any <p> tag will override the default
<p> CSS. If the CSS class uses a CSS attribute already defined by the default CSS,
then the formatting defined by the class will be the value that is used.
It may be easier to imagine that the CSS for a generic HTML element is the
starting point and the only way to change that look is to overwrite the attributes
using CSS classes. Please see the example below for a visual of this tricky topic.
CSS Code:
Web Reference
HTML Reference
CSS Reference
CSS Examples
PHP Examples
Help Tizag Grow
Link to Tizag
New - Tizag.com Forums!
Recent Forum Topics:
- Which Laptop(s) and Notebook
(s) could u recommend?
- Obhosting | unlimited reseller &
master reseller hosting | 20%off
- linked text
- call a function
Advertise Here
More Tutorials!
Microsoft Office Tutorials
Artist Tutorials
p.first{ color: blue; }
p.second{ color: red; }
<html>
<body>
<p>This is a normal paragraph.</p>
<p class="first">This is a paragraph that uses the p.first CSS code!</p>
<p class="second">This is a paragraph that uses the p.second CSS code!</p>
...
p{ color: red; font-size: 20px; }
p.test1{ color: blue; }
p.test2{ font-size: 12px; }
Page 1 of 2CSS Tutorial - Class
9/28/2010http://www.tizag.com/cssT/class.php
Go Back Continue
HTML Code:
Display:
This is a normal paragraph.
This is a paragraph that uses the p.test1
CSS code! The p.test1 paragraph remained
the same size, but it's color changed.
This is a paragraph that uses the p.test2 CSS code! The p.test2
paragraph remained the same color, but it's size changed.
Remember, CSS code in classes will override the general CSS code for that
element. p.test1 overrides p!
foundsomethingwronginthislesson?
Report a Bug or Comment on This Lesson - Your input is what keeps Tizag
improving with time!
Try it out!
<html>
<head>
<style>
p.first { background-color: gray; }
p.second { background-color: red; }
p.third {
background: purple;
color: white;
}
</style>
</head>
<body>
<h2>CSS Classes</h2>
<p class="first">This is the p.first paragraph</p>
<p class="second">This is the p.second paragraph</p>
<p class="third">This is the p.third paragraph</p>
Submit Query
2003-2008 Erack Network | Copyright | Privacy Policy | Advertising Information
Site design by Seattle Web Design
<html>
<body>
<p>This is a normal paragraph.</p>
<p class="test1">This is a paragraph that uses the p.test1 CSS code!</p>
<p class="test2">This is a paragraph that uses the p.test2 CSS code!</p>
...
Ads by Google CSS Web Design Free PHP Code CSS Servers MySQL Tutorial
Page 2 of 2CSS Tutorial - Class
9/28/2010http://www.tizag.com/cssT/class.php

More Related Content

PPTX
Rakshat bhati
PPTX
Html Css Mistakes
ODP
Static websites assignment 1 - CIT012753
PDF
Html css
PPT
CSS Fundamentals
PDF
Intro to css & sass
PDF
Css introduction
KEY
Intro to SASS CSS
Rakshat bhati
Html Css Mistakes
Static websites assignment 1 - CIT012753
Html css
CSS Fundamentals
Intro to css & sass
Css introduction
Intro to SASS CSS

What's hot (19)

ODP
Cascading Style Sheets - Part 02
PPTX
Kristina benjamin fonttag
PPT
INFO3775 Chapter 2 Part 2
PDF
Efficient, maintainable CSS
PDF
Inline, Block and Positioning in CSS
PDF
Pemrograman Web 2 - CSS
PPTX
David Weliver
PDF
Pemrograman Web 4 - Bootstrap 3
PDF
Haml And Sass In 15 Minutes
PPT
Spectrum 2015 going online with style - an intro to css
PDF
Links and Navigation
PPTX
Css with example
PDF
Pemrograman Web 3 - CSS Basic Part 2
PDF
Visualizing The Code
PPTX
CSS Basics - Stylesheets and Color
PPTX
Html & CSS
PDF
Intro to CSS
PPT
How to manage a big scale HTML/CSS project
PDF
Introduction to css
Cascading Style Sheets - Part 02
Kristina benjamin fonttag
INFO3775 Chapter 2 Part 2
Efficient, maintainable CSS
Inline, Block and Positioning in CSS
Pemrograman Web 2 - CSS
David Weliver
Pemrograman Web 4 - Bootstrap 3
Haml And Sass In 15 Minutes
Spectrum 2015 going online with style - an intro to css
Links and Navigation
Css with example
Pemrograman Web 3 - CSS Basic Part 2
Visualizing The Code
CSS Basics - Stylesheets and Color
Html & CSS
Intro to CSS
How to manage a big scale HTML/CSS project
Introduction to css

Similar to Class (20)

PDF
Structuring your CSS for maintainability: rules and guile lines to write CSS
PDF
Introduction to css
PPTX
INTRODUCTIONS OF CSS
PPT
CSS Methodology
PPT
Css training tutorial css3 &amp; css4 essentials
PDF
A complete html and css guidelines for beginners
PPT
Css Founder.com | Cssfounder org
PPT
css Cascading Style Sheets (CSS) - control the look and feel of your HTML doc...
PDF
The CSS Handbook
PPT
CSS Basic and Common Errors
PDF
Intro to HTML and CSS - Class 2 Slides
PPT
Rational HATS and CSS
PDF
HowTo_CSS
PDF
HowTo_CSS
PPT
Basics Of Css And Some Common Mistakes
PPT
CSS Overview
PDF
DOCX
PPT
Unit 2-CSS & Bootstrap.ppt
Structuring your CSS for maintainability: rules and guile lines to write CSS
Introduction to css
INTRODUCTIONS OF CSS
CSS Methodology
Css training tutorial css3 &amp; css4 essentials
A complete html and css guidelines for beginners
Css Founder.com | Cssfounder org
css Cascading Style Sheets (CSS) - control the look and feel of your HTML doc...
The CSS Handbook
CSS Basic and Common Errors
Intro to HTML and CSS - Class 2 Slides
Rational HATS and CSS
HowTo_CSS
HowTo_CSS
Basics Of Css And Some Common Mistakes
CSS Overview
Unit 2-CSS & Bootstrap.ppt

More from Daniel Downs (20)

PPT
Developing a mobile application curriculum which empowers authentic
PDF
Module11: Creating A External Style Sheet and Creating A Gallery
PDF
Seo continued page 2
PDF
Module 10search engine optimization
PDF
Ipad quick-reference-2
PDF
Index of jquery template 2 Minuteman Summer Web Dev.
PDF
Jquery template 1 3 pages
PDF
Module6 htmlcss helpfulcodeandwebsites
PDF
Module 4 Minuteman Lexington Web Design Daniel Downs
PDF
Module 3 Progress Codes Web Design Daniel Downs Minuteman Lexington Ma
PDF
Module 2 lexington minuteman web development basic layout template
PDF
Module 1 Web design & Development Lexington Minuteman
PDF
App research project
PDF
Daniel Downs: Student Experiences In A Project Based Learning Technology Curr...
PDF
Blogger custom domain on go daddy blogger widgets
PDF
Outline for action research prospectus
PDF
You have decided to go off on your own as a freelance webdesigner
PDF
Making a basicappinflash (1)
PDF
Daniel Downs Technology Portfolio Final May 2013 final (1)
PDF
Web design 1& 2 lesson outline
Developing a mobile application curriculum which empowers authentic
Module11: Creating A External Style Sheet and Creating A Gallery
Seo continued page 2
Module 10search engine optimization
Ipad quick-reference-2
Index of jquery template 2 Minuteman Summer Web Dev.
Jquery template 1 3 pages
Module6 htmlcss helpfulcodeandwebsites
Module 4 Minuteman Lexington Web Design Daniel Downs
Module 3 Progress Codes Web Design Daniel Downs Minuteman Lexington Ma
Module 2 lexington minuteman web development basic layout template
Module 1 Web design & Development Lexington Minuteman
App research project
Daniel Downs: Student Experiences In A Project Based Learning Technology Curr...
Blogger custom domain on go daddy blogger widgets
Outline for action research prospectus
You have decided to go off on your own as a freelance webdesigner
Making a basicappinflash (1)
Daniel Downs Technology Portfolio Final May 2013 final (1)
Web design 1& 2 lesson outline

Class

  • 1. Search Home Web Tutorials Beginner Tutorial HTML Tutorial CSS Tutorial Scripting Javascript Tutorial PHP Tutorial Perl Tutorial Ajax Tutorial ASP Tutorial VBScript Tutorial Databases SQL Tutorial MySQL Tutorial Miscellaneous XML Tutorial Webhost Tutorial Flash Tutorial SEO Tutorial CSS Tutorial CSS - Introduction CSS - Selector CSS - Internal CSS - External CSS - Inline CSS - Class CSS - Background CSS - Font CSS - Text CSS - Padding CSS - Margin CSS - Border CSS - List CSS - Pseudo Class & Mouseover Advanced Topics CSS - Cursor CSS - Properties CSS - Position CSS - Layers CSS - Float CSS - ID vs Class CSS - Display Get Help! CSS Forum Contact Us cssclasses You may be wondering if it is possible to give an HTML element multiple looks with CSS. Say for example that sometimes you want the font to be large and white, while other times you would prefer the font to be small and black. CSS would not be very useful if it did not allow you to have many different types of formats for a single HTML tag. Well, you are in luck! CSS allows you to do just that with the use of classes. Advertise on Tizag.com the formatofclasses Using classes is simple. You just need to add an extension to the typical CSS code and make sure you specify this extension in your HTML. Let's try this with an example of making two paragraphs that behave differently. First, we begin with the CSS code, note the red text. CSS Code: HTML Code: Display: This is a normal paragraph. This is a paragraph that uses the p.first CSS code! This is a paragraph that uses the p.second CSS code! You can use CSS classes with any HTML element! However, what happens if we had already defined a value for the default <p> tag, would this cause any problems for classes of the paragraph tag? Well, when this happens the CSS class for any <p> tag will override the default <p> CSS. If the CSS class uses a CSS attribute already defined by the default CSS, then the formatting defined by the class will be the value that is used. It may be easier to imagine that the CSS for a generic HTML element is the starting point and the only way to change that look is to overwrite the attributes using CSS classes. Please see the example below for a visual of this tricky topic. CSS Code: Web Reference HTML Reference CSS Reference CSS Examples PHP Examples Help Tizag Grow Link to Tizag New - Tizag.com Forums! Recent Forum Topics: - Which Laptop(s) and Notebook (s) could u recommend? - Obhosting | unlimited reseller & master reseller hosting | 20%off - linked text - call a function Advertise Here More Tutorials! Microsoft Office Tutorials Artist Tutorials p.first{ color: blue; } p.second{ color: red; } <html> <body> <p>This is a normal paragraph.</p> <p class="first">This is a paragraph that uses the p.first CSS code!</p> <p class="second">This is a paragraph that uses the p.second CSS code!</p> ... p{ color: red; font-size: 20px; } p.test1{ color: blue; } p.test2{ font-size: 12px; } Page 1 of 2CSS Tutorial - Class 9/28/2010http://www.tizag.com/cssT/class.php
  • 2. Go Back Continue HTML Code: Display: This is a normal paragraph. This is a paragraph that uses the p.test1 CSS code! The p.test1 paragraph remained the same size, but it's color changed. This is a paragraph that uses the p.test2 CSS code! The p.test2 paragraph remained the same color, but it's size changed. Remember, CSS code in classes will override the general CSS code for that element. p.test1 overrides p! foundsomethingwronginthislesson? Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time! Try it out! <html> <head> <style> p.first { background-color: gray; } p.second { background-color: red; } p.third { background: purple; color: white; } </style> </head> <body> <h2>CSS Classes</h2> <p class="first">This is the p.first paragraph</p> <p class="second">This is the p.second paragraph</p> <p class="third">This is the p.third paragraph</p> Submit Query 2003-2008 Erack Network | Copyright | Privacy Policy | Advertising Information Site design by Seattle Web Design <html> <body> <p>This is a normal paragraph.</p> <p class="test1">This is a paragraph that uses the p.test1 CSS code!</p> <p class="test2">This is a paragraph that uses the p.test2 CSS code!</p> ... Ads by Google CSS Web Design Free PHP Code CSS Servers MySQL Tutorial Page 2 of 2CSS Tutorial - Class 9/28/2010http://www.tizag.com/cssT/class.php