SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Downloaden Sie, um offline zu lesen
CSS
What is CSS?
• CSS stands for Cascading Style Sheets
• Styles define how to display HTML elements
• Styles are added to HTML 4.0
• External Style Sheets are stored in CSS files
Styles Solved a Big Problem
• HTML was never intended to contain tags for formatting a document
• When tags like <font>, and color attributes were added to the HTML
3.2 specification, it started a nightmare for web developers.
• To solve this problem, the World Wide Web Consortium (W3C)
created CSS.
• In HTML 4.0, all formatting could be removed from the HTML
document, and stored in a separate CSS file.
• All browsers support CSS today.
CSS Saves a Lot of Work!
• CSS defines HOW HTML elements are to be displayed
• Styles are normally saved in external .css files
• External style sheets enable you to change the appearance and layout
of all the pages in a Web site, just by editing one single file!
CSS Syntax
• A CSS rule has two main parts: a selector, and one or more
declarations:
• The selector is normally the HTML element you want to style.
• Each declaration consists of a property and a value.
• The property is the style attribute you want to change.
• Each property has a value.
CSS Selectors
• Three types of CSS Selectors
• Element
• Class
• ID
CSS Element Selector Example
• A CSS declaration always ends with a semicolon, and declaration
groups are surrounded by curly brackets:
• p {color:red;text-align:center;}
• To make the CSS more readable, you can put one declaration on each
line, like this:
• p { color:red;
text-align:center;
}
CSS Comments
• Are used to explain code, and may help to edit the source code at a
later
• Are ignored by browsers
• A CSS comment begins with "/*", and ends with "*/"
• p{
text-align:center;
/*This is another comment*/
color:black;
font-family:arial;
}
The id and class Selectors
• In addition to setting a style for a HTML element, CSS allows you to
specify our own selectors which are:
• Id
• Class
The id Selector
• The id selector is used to specify a style for a single, unique element.
• The id selector uses the id attribute of the HTML element, and is
defined with a "#".
• Example
• Imagine within the body element of our html page, we have the following
paragraph element
<p id=”welcome”>Welcome to the wonderful world of HTML</p>
• We can then create a CSS rule with the id selector:
#welcome { text-align:center; color:red; }
The class Selector
• Is used to specify a style for a group of elements
• Unlike the id selector, the class selector is most often used on several
elements
• This allows you to set a particular style for many HTML elements with
the same class.
• The class selector uses the HTML class attribute, and is defined with a
"."
• Example:
• Imagine within the body element of our html page, we have the
following header element
<h2 class=”center”>Summary</h2>
• We can then create a CSS rule with the class selector:
.center {text-align:center;}
• Can also specify that only specific HTML elements should be affected
by a class
• In the example below, all p elements with class="center" will be
center-aligned:
• Example
p.center {text-align:center;}
CSS Box Model
Three Ways to Insert CSS
• External style sheet
• Internal style sheet
• Inline style
External Style Sheet
• An external style sheet is ideal when the style is applied to many
pages
• With an external style sheet, you can change the look of an entire
Web site by changing one file.
• Each page must link to the style sheet using the <link> tag.
• An external style sheet can be written in any text editor.
• The file should not contain any html tags.
• Your style sheet should be saved with a .css extension.
• Example:
Internal Style Sheet
• An internal style sheet should be used when a single document has a
unique style.
• You define internal styles in the head section of an HTML page, by
using the <style> tag
Inline Styles
• An inline style loses many of the advantages of style sheets by mixing
content with presentation.
• To use inline styles you use the style attribute in the relevant tag.
• The style attribute can contain any CSS property.
• Example:
• Multiple styles are cascaded in to one style.
• The order of priority is(first is of the least priority):
• Browser default
• External style sheet
• Internal style sheet (in the head section)
• Inline style (inside an HTML element)
CSS Background Properties
• background-color
• background-image
• background-repeat
CSS Border Properties
• border-style can have the following values:
• none: Defines no border
• dotted: Defines a dotted border
• dashed: Defines a dashed border
• solid: Defines a solid border
• border-width property is used to set the width of the border
• border-color property is used to set the color of the border.
• The color can be set by:
• name - specify a color name, like "red“
• RGB - specify a RGB value, like "rgb(255,0,0)“
• Hex - specify a hex value, like "#ff0000"
• color property is used to set the color of the text
• text-align property is used to set the horizontal alignment of a text
• text-decoration property is used to set or remove decorations from
text
• text-transform property is used to specify uppercase and lowercase
letters in a text
• Can be used to turn everything into uppercase or lowercase letters, or
capitalize the first letter of each word
• text-indent property is used to specify the indentation
Grouping Selectors
Nesting Selectors
What is CSS Float?
• With CSS float, an element can be pushed to the left or right, allowing
other elements to wrap around it
• Float is very often used for images, but it is also useful when working
with layouts
Turning off Float
Navigation Bars
• Having easy-to-use navigation is important for any web site
• With CSS you can transform boring HTML menus into good-looking
navigation bars
• Navigation Bar = List of Links
Vertical Navigation Bar
height
Horizontal Navigation Bar
• There are two ways to create a horizontal navigation bar
• Using inline list items
• Using floating list items
• Both methods work fine, but if you want the links to be the same size,
you have to use the floating method.
Inline List Items
• One way to build a horizontal navigation bar is to specify the <li>
elements as inline, in addition to the "standard" code above
Floating List Items
• In the example above the links have different widths
• For all the links to have an equal width, float the <li> elements and
specify a width for the <a> elements

Weitere ähnliche Inhalte

Was ist angesagt? (19)

HTML and XML Difference FAQs
HTML and XML Difference FAQsHTML and XML Difference FAQs
HTML and XML Difference FAQs
 
Xml
XmlXml
Xml
 
Xml
XmlXml
Xml
 
Unit iv xml
Unit iv xmlUnit iv xml
Unit iv xml
 
Publishing xml
Publishing xmlPublishing xml
Publishing xml
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
XML for beginners
XML for beginnersXML for beginners
XML for beginners
 
Xml unit1
Xml unit1Xml unit1
Xml unit1
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Xml Lecture Notes
Xml Lecture NotesXml Lecture Notes
Xml Lecture Notes
 
Web Development - Lecture 5
Web Development - Lecture 5Web Development - Lecture 5
Web Development - Lecture 5
 
Xml basics for beginning
Xml basics for beginningXml basics for beginning
Xml basics for beginning
 
Web Development - Lecture 4
Web Development - Lecture 4Web Development - Lecture 4
Web Development - Lecture 4
 
Basics of XML
Basics of XMLBasics of XML
Basics of XML
 
Web Development - Lecture 3
Web Development - Lecture 3Web Development - Lecture 3
Web Development - Lecture 3
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Xml
XmlXml
Xml
 
Unit3wt
Unit3wtUnit3wt
Unit3wt
 
uptu web technology unit 2 html
uptu web technology unit 2 htmluptu web technology unit 2 html
uptu web technology unit 2 html
 

Ähnlich wie Css (20)

css.ppt
css.pptcss.ppt
css.ppt
 
Css
CssCss
Css
 
basic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdfbasic programming language AND HTML CSS JAVApdf
basic programming language AND HTML CSS JAVApdf
 
BITM3730 9-19.pptx
BITM3730 9-19.pptxBITM3730 9-19.pptx
BITM3730 9-19.pptx
 
BITM3730 9-20.pptx
BITM3730 9-20.pptxBITM3730 9-20.pptx
BITM3730 9-20.pptx
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
CSS Comprehensive Overview
CSS Comprehensive OverviewCSS Comprehensive Overview
CSS Comprehensive Overview
 
Css
CssCss
Css
 
BITM3730Week4.pptx
BITM3730Week4.pptxBITM3730Week4.pptx
BITM3730Week4.pptx
 
CSS Basics part One
CSS Basics part OneCSS Basics part One
CSS Basics part One
 
CSS tutorial chapter 1
CSS tutorial chapter 1CSS tutorial chapter 1
CSS tutorial chapter 1
 
WEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptxWEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptx
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
CSS Introduction
CSS Introduction CSS Introduction
CSS Introduction
 
Html
HtmlHtml
Html
 
Intro to html, css & sass
Intro to html, css & sassIntro to html, css & sass
Intro to html, css & sass
 
Css types internal, external and inline (1)
Css types internal, external and inline (1)Css types internal, external and inline (1)
Css types internal, external and inline (1)
 
Css
CssCss
Css
 
DHTML
DHTMLDHTML
DHTML
 
Ifi7174 lesson2
Ifi7174 lesson2Ifi7174 lesson2
Ifi7174 lesson2
 

Mehr von Kamal Acharya

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computerKamal Acharya
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer SecurityKamal Acharya
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHPKamal Acharya
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in phpKamal Acharya
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPKamal Acharya
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data WarehousingKamal Acharya
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data MiningKamal Acharya
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data MiningKamal Acharya
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data miningKamal Acharya
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingKamal Acharya
 

Mehr von Kamal Acharya (20)

Programming the basic computer
Programming the basic computerProgramming the basic computer
Programming the basic computer
 
Computer Arithmetic
Computer ArithmeticComputer Arithmetic
Computer Arithmetic
 
Introduction to Computer Security
Introduction to Computer SecurityIntroduction to Computer Security
Introduction to Computer Security
 
Session and Cookies
Session and CookiesSession and Cookies
Session and Cookies
 
Functions in php
Functions in phpFunctions in php
Functions in php
 
Web forms in php
Web forms in phpWeb forms in php
Web forms in php
 
Making decision and repeating in PHP
Making decision and repeating  in PHPMaking decision and repeating  in PHP
Making decision and repeating in PHP
 
Working with arrays in php
Working with arrays in phpWorking with arrays in php
Working with arrays in php
 
Text and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHPText and Numbers (Data Types)in PHP
Text and Numbers (Data Types)in PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
Capacity Planning of Data Warehousing
Capacity Planning of Data WarehousingCapacity Planning of Data Warehousing
Capacity Planning of Data Warehousing
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Search Engines
Search EnginesSearch Engines
Search Engines
 
Web Mining
Web MiningWeb Mining
Web Mining
 
Information Privacy and Data Mining
Information Privacy and Data MiningInformation Privacy and Data Mining
Information Privacy and Data Mining
 
Cluster Analysis
Cluster AnalysisCluster Analysis
Cluster Analysis
 
Association Analysis in Data Mining
Association Analysis in Data MiningAssociation Analysis in Data Mining
Association Analysis in Data Mining
 
Classification techniques in data mining
Classification techniques in data miningClassification techniques in data mining
Classification techniques in data mining
 
Data Preprocessing
Data PreprocessingData Preprocessing
Data Preprocessing
 
Introduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data WarehousingIntroduction to Data Mining and Data Warehousing
Introduction to Data Mining and Data Warehousing
 

Kürzlich hochgeladen

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 

Kürzlich hochgeladen (20)

Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 

Css

  • 1. CSS
  • 2. What is CSS? • CSS stands for Cascading Style Sheets • Styles define how to display HTML elements • Styles are added to HTML 4.0 • External Style Sheets are stored in CSS files
  • 3. Styles Solved a Big Problem • HTML was never intended to contain tags for formatting a document • When tags like <font>, and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers. • To solve this problem, the World Wide Web Consortium (W3C) created CSS. • In HTML 4.0, all formatting could be removed from the HTML document, and stored in a separate CSS file. • All browsers support CSS today.
  • 4. CSS Saves a Lot of Work! • CSS defines HOW HTML elements are to be displayed • Styles are normally saved in external .css files • External style sheets enable you to change the appearance and layout of all the pages in a Web site, just by editing one single file!
  • 5. CSS Syntax • A CSS rule has two main parts: a selector, and one or more declarations: • The selector is normally the HTML element you want to style. • Each declaration consists of a property and a value. • The property is the style attribute you want to change. • Each property has a value.
  • 6. CSS Selectors • Three types of CSS Selectors • Element • Class • ID
  • 7. CSS Element Selector Example • A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly brackets: • p {color:red;text-align:center;} • To make the CSS more readable, you can put one declaration on each line, like this: • p { color:red; text-align:center; }
  • 8. CSS Comments • Are used to explain code, and may help to edit the source code at a later • Are ignored by browsers • A CSS comment begins with "/*", and ends with "*/" • p{ text-align:center; /*This is another comment*/ color:black; font-family:arial; }
  • 9. The id and class Selectors • In addition to setting a style for a HTML element, CSS allows you to specify our own selectors which are: • Id • Class
  • 10. The id Selector • The id selector is used to specify a style for a single, unique element. • The id selector uses the id attribute of the HTML element, and is defined with a "#". • Example • Imagine within the body element of our html page, we have the following paragraph element <p id=”welcome”>Welcome to the wonderful world of HTML</p> • We can then create a CSS rule with the id selector: #welcome { text-align:center; color:red; }
  • 11. The class Selector • Is used to specify a style for a group of elements • Unlike the id selector, the class selector is most often used on several elements • This allows you to set a particular style for many HTML elements with the same class. • The class selector uses the HTML class attribute, and is defined with a "."
  • 12. • Example: • Imagine within the body element of our html page, we have the following header element <h2 class=”center”>Summary</h2> • We can then create a CSS rule with the class selector: .center {text-align:center;}
  • 13. • Can also specify that only specific HTML elements should be affected by a class • In the example below, all p elements with class="center" will be center-aligned: • Example p.center {text-align:center;}
  • 15. Three Ways to Insert CSS • External style sheet • Internal style sheet • Inline style
  • 16. External Style Sheet • An external style sheet is ideal when the style is applied to many pages • With an external style sheet, you can change the look of an entire Web site by changing one file. • Each page must link to the style sheet using the <link> tag.
  • 17. • An external style sheet can be written in any text editor. • The file should not contain any html tags. • Your style sheet should be saved with a .css extension. • Example:
  • 18. Internal Style Sheet • An internal style sheet should be used when a single document has a unique style. • You define internal styles in the head section of an HTML page, by using the <style> tag
  • 19. Inline Styles • An inline style loses many of the advantages of style sheets by mixing content with presentation. • To use inline styles you use the style attribute in the relevant tag. • The style attribute can contain any CSS property. • Example:
  • 20. • Multiple styles are cascaded in to one style. • The order of priority is(first is of the least priority): • Browser default • External style sheet • Internal style sheet (in the head section) • Inline style (inside an HTML element)
  • 21. CSS Background Properties • background-color • background-image • background-repeat
  • 22. CSS Border Properties • border-style can have the following values: • none: Defines no border • dotted: Defines a dotted border • dashed: Defines a dashed border • solid: Defines a solid border
  • 23. • border-width property is used to set the width of the border
  • 24. • border-color property is used to set the color of the border. • The color can be set by: • name - specify a color name, like "red“ • RGB - specify a RGB value, like "rgb(255,0,0)“ • Hex - specify a hex value, like "#ff0000"
  • 25. • color property is used to set the color of the text
  • 26. • text-align property is used to set the horizontal alignment of a text
  • 27. • text-decoration property is used to set or remove decorations from text
  • 28. • text-transform property is used to specify uppercase and lowercase letters in a text • Can be used to turn everything into uppercase or lowercase letters, or capitalize the first letter of each word
  • 29. • text-indent property is used to specify the indentation
  • 32. What is CSS Float? • With CSS float, an element can be pushed to the left or right, allowing other elements to wrap around it • Float is very often used for images, but it is also useful when working with layouts
  • 34. Navigation Bars • Having easy-to-use navigation is important for any web site • With CSS you can transform boring HTML menus into good-looking navigation bars • Navigation Bar = List of Links
  • 35.
  • 37. Horizontal Navigation Bar • There are two ways to create a horizontal navigation bar • Using inline list items • Using floating list items • Both methods work fine, but if you want the links to be the same size, you have to use the floating method.
  • 38. Inline List Items • One way to build a horizontal navigation bar is to specify the <li> elements as inline, in addition to the "standard" code above
  • 39. Floating List Items • In the example above the links have different widths • For all the links to have an equal width, float the <li> elements and specify a width for the <a> elements