SlideShare a Scribd company logo
1 of 29
Adeel Rasheed
Custom Web Application Developer
 https://chauhantricks.blogspot.com
 https://www.fiverr.com/adeelrasheed
What is CSS?
CSS stands for Cascading Style Sheets
CSS describes how HTML elements
are to be displayed on screen
CSS saves a lot of work. It can
control the layout of multiple web
pages all at once
CSS Syntax
 A CSS comprises of style rules that are interpreted by the
browser and then applied to the corresponding elements in
your document.
 A style rule is made of three parts −
 Selector − A selector is an HTML tag at which a style will
be applied. This could be any tag like <h1> or <table> etc.
 Property - A property is a type of attribute of HTML tag.
Put simply, all the HTML attributes are converted into CSS
properties. They could be color, border etc.
 Value - Values are assigned to properties. For
example, colorproperty can have value
either red or #F1F1F1 etc.
CSS Syntax
selector { property: value }
You can put CSS Style Rule Syntax as
follows −
Example
p {
color: red;
text-align: center;
}
CSS Selectors
 Selectors are one of the most important aspects of CSS as they are used to select elements on a web
page so that they can be styled.
1-Element Type Selector
 An element type selector matches every instance of the element in the document tree with the
corresponding element type name.
Example
p {
color: blue;
}
2-Id Selectors
The id selector is used to define style rules for a single or unique element.
The id selector is defined with a '#' (hash) sign immediately followed by the id value.
Example
#error {
color: red;
}
3-Class Selector
 The class selector selects elements with a specific class attribute.
 To select elements with a specific class, write a period (.) character, followed by the name of the class.
Example
.center {
text-align: center;
color: red;
}
Inserting CSS
Three Ways to Insert CSS
 External style sheet
 Internal style sheet
 Inline style
External Style Sheet
 With an external style sheet, you can change the
look of an entire website by changing just one file!
 Each page must include a reference to the external
style sheet file inside the <link> element. The
<link> element goes inside the <head> section:
 The style sheet file must be saved with a .css extension.
Example
 <head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
Internal Style Sheet
 An internal style sheet may be used if one single page has a unique style.
 Internal styles are defined within the <style> element, inside the <head>
section of an HTML page:
Example
 <head>
<style>
body {
background-color: linen;
}
h1 {
color: maroon;
margin-left: 40px;
}
</style>
</head>
Inline Styles
 An inline style may be used to apply a unique style for
a single element.
 To use inline styles, add the style attribute to the
relevant element. The style attribute can contain any
CSS property.
 The example below shows how to change the color and
the left margin of a <h1> element:
Example
 <h1 style="color:blue;margin-left:30px;">This is a
heading.</h1>
Color property
Colors in CSS are most often specified by:
 a valid color name - like "red"
 an RGB value - like "rgb(255, 0, 0)"
 a HEX value - like "#ff0000"
Background property
Element Property Initial value
'background-attachment' scroll | fixed | inherit scroll
'background-color' <color> | transparent | inherit transparent
'background-image' <url> | none | inherit none
'background-position'
[ [ <percentage> | <length> | left | center | right ]
[ <percentage> |<length> | top | center | bottom ]? ]
| [ [ left | center | right ] || [ top | center | bottom ] ]
| inherit 0% 0%
'background-repeat' repeat | repeat-x | repeat-y | no-repeat | inherit repeat
'background'
['background-color' || 'background-
image' || 'background-repeat' ||'background-
attachment' ||'background-position'] | inherit
see individual
properties
Border propertyElement Property Initial value
'border-color' [ <color> |
see individual
properties
'border-spacing' <length> <length>? 0
'border-style'
None,solid,dotted,dashed,double,groove,ridge,
inset,outset,hidden
see individual
properties
'border-top''border-right''border-
bottom''border-left'
[ <border-width> || <border-style> ||'border-top-
color' ]
see individual
properties
'border-top-color' 'border-right-
color''border-bottom-color' 'border-left-
color' <color>
the value of the
'color' property
'border-top-style' 'border-right-
style''border-bottom-style' 'border-left-
style' <border-style> None
'border-top-width' 'border-right-
width''border-bottom-width' 'border-left-
width' <border-width> medium
'border-width'
length in px, pt or cm or it should be set
to thin, medium or thick.
see individual
properties
'border' [ <border-width> || <border-style> ||'border-color' ]
see individual
properties
Round Border property
Element Property Initial value
'border-radius’ In pixels
see
individual
properties
'border-top-right-radius'‘
'border-top-left-radius‘‘
'border-botttom-right-radius'‘
'border-bottom-left-radius‘‘ In pixels
see
individual
properties
Outline Property
 An outline is a line that is drawn around elements
(outside the borders) to make the element "stand out".
 Similar to border
 Outline Sets all the outline properties in one
declaration
 outline-color Sets the color of an outline
 outline-offset Specifies the space between an outline
and the edge or border of an element
 outline-styleSets the style of an outline
 outline-widthSets the width of an outline
Font property
Element Property
'font-family'
[[ <family-name> | <generic-family>] [, <family-name>| <generic-family>]* ] | inherit
Example: font-family: "Times New Roman", Times, serif;
'font-size'
<absolute-size> | <relative-size> |<length> |
keywords: xx-small, x-small, small, medium, large, x-large, xx-large.
size in pixel values (e.g. 12px, 16px, etc.)
'font-style' normal | italic | oblique | inherit
'font-variant' normal | small-caps | inherit
'font-weight'
normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
| inherit
'font'
[ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height']? 'font-family' ] |
caption | icon | menu | message-box | small-caption | status-bar | inherit
'height' <length> | <percentage> | auto |inherit
'letter-spacing' normal | <length> | inherit
'line-height' normal | <number> | <length> |<percentage> | inherit
Text propertyElement Property Initial value
'text-align' left | right | center | justify | inherit
a nameless value
that acts as 'left' if
'direction' is 'ltr',
'right' if 'direction' is
'rtl'
'text-decoration'
none | [ underline || overline || line-through || blink
] | inherit none
'text-indent' <length> | <percentage> | inherit 0
'text-transform' capitalize | uppercase | lowercase | none | inherit none
'text-align' left | right | center | justify | inherit
a nameless value
that acts as 'left' if
'direction' is 'ltr',
'right' if 'direction' is
'rtl'
The BOX Model
 The following diagram demonstrates how the margin, padding, and
border CSS properties determines how much space an element can
take on a web page.
CSS Margins
 The CSS margin properties are used to generate space
around elements.
 The margin properties set the size of the white space
outside the border.
 margin-top
 margin-right
 margin-bottom
 margin-left
 All the margin properties can have the following values:
 auto - the browser calculates the margin
 length - specifies a margin in px, pt, cm, etc.
 % - specifies a margin in % of the width of the containing element
 inherit - specifies that the margin should be inherited from the parent
element
CSS Margins
Example
 p {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
Example shorthand
 p {
margin: 100px 150px 100px 80px;
margin: 25px 50px 75px 100px;
}
CSS Margins
 If the margin property has four values:
 margin: 25px 50px 75px 100px;
 top margin is 25px
 right margin is 50px
 bottom margin is 75px
 left margin is 100px
 If the margin property has three values:
 margin: 25px 50px 75px;
 top margin is 25px
 right and left margins are 50px
 bottom margin is 75px
 If the margin property has two values:
 margin: 25px 50px;
 top and bottom margins are 25px
 right and left margins are 50px
 If the margin property has one value:
 margin: 25px;
 all four margins are 25px
CSS Padding
 The CSS padding properties are used to generate space around content.
 The padding clears an area around the content (inside the border) of an element.
 CSS has properties for specifying the padding for each side of an element:
 padding-top
 padding-right
 padding-bottom
 padding-left
Example
p {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}
Padding shorthand
 p {
padding: 50px 30px 50px 80px;
}
CSS Height and Width
 The height and width properties are used to set the height
and width of an element.
 The height and width can be set to auto (this is default.
Means that the browser calculates the height and width),
or be specified in length values, like px, cm, etc., or in
percent (%) of the containing block.
 Example
 div {
height: 200px;
width: 50%;
background-color: powderblue;
}
CSS Height and Width
 All CSS Dimension Properties
 Height Sets the height of an element
 max-height Sets the maximum height of an element
 max-width Sets the maximum width of an element
 min-height Sets the minimum height of an element
 min-width Sets the minimum width of an element
 Width Sets the width of an element
CSS Links
 With CSS, links can be styled in different ways.
links can be styled differently depending on
what state they are in.
The four links states are:
•a:link - a normal, unvisited link
•a:visited - a link the user has visited
•a:hover - a link when the user mouses over it
•a:active - a link the moment it is clicked
CSS Links
Example
/* unvisited link */
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
/* mouse over link */
a:hover {
color: hotpink;
}
/* selected link */
a:active {
color: blue;
}
CSS Tables
Adding Borders to Tables
 The CSS border property is the best way to define the
borders for the tables.
 The following example will set a black border for
the <table>, <th>, and <td> elements.
Example
table, th, td {
border: 1px solid black;
}
CSS Tables
Adding Borders to Tables
 The border-collapse CSS property selects a table's border model.
 It can accept one of the two values collapse or separate.
 The separated model is the default HTML table border model in which
each Adjacent cells have their own distinct borders.
 In the collapsed border model, adjacent table cells share borders.
Example
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
CSS Tables
 Striped Tables
 For zebra-striped tables, use the nth-child() selector and add
a background-color to all even (or odd) table rows:
Example
 tr:nth-child(even) {background-color: #f2f2f2}

More Related Content

What's hot

What's hot (20)

Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3Web Design Course: CSS lecture 3
Web Design Course: CSS lecture 3
 
Beginners css tutorial for web designers
Beginners css tutorial for web designersBeginners css tutorial for web designers
Beginners css tutorial for web designers
 
CSS Basics part One
CSS Basics part OneCSS Basics part One
CSS Basics part One
 
CSS tutorial chapter 2
CSS tutorial chapter 2CSS tutorial chapter 2
CSS tutorial chapter 2
 
CSS tutorial chapter 3
CSS tutorial chapter 3CSS tutorial chapter 3
CSS tutorial chapter 3
 
CSS Walktrough Internship Course
CSS Walktrough Internship CourseCSS Walktrough Internship Course
CSS Walktrough Internship Course
 
Cascading style sheets - CSS
Cascading style sheets - CSSCascading style sheets - CSS
Cascading style sheets - CSS
 
Css lecture notes
Css lecture notesCss lecture notes
Css lecture notes
 
Css
CssCss
Css
 
Css
CssCss
Css
 
CSS Part I
CSS Part ICSS Part I
CSS Part I
 
Basic-CSS-tutorial
Basic-CSS-tutorialBasic-CSS-tutorial
Basic-CSS-tutorial
 
Pemrograman Web 2 - CSS
Pemrograman Web 2 - CSSPemrograman Web 2 - CSS
Pemrograman Web 2 - CSS
 
Css
CssCss
Css
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
 
Web Design Course: CSS lecture 4
Web Design Course: CSS  lecture 4Web Design Course: CSS  lecture 4
Web Design Course: CSS lecture 4
 
CSS
CSS CSS
CSS
 
CSS
CSSCSS
CSS
 
Web Engineering - Basic CSS Properties
Web Engineering - Basic CSS PropertiesWeb Engineering - Basic CSS Properties
Web Engineering - Basic CSS Properties
 
CSS ppt
CSS pptCSS ppt
CSS ppt
 

Similar to CSS Cascade Style Sheet

cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
tutorialsruby
 

Similar to CSS Cascade Style Sheet (20)

Css
CssCss
Css
 
Css
CssCss
Css
 
5. Web Technology CSS Advanced
5. Web Technology CSS Advanced 5. Web Technology CSS Advanced
5. Web Technology CSS Advanced
 
Web Engineering - Introduction to CSS
Web Engineering - Introduction to CSSWeb Engineering - Introduction to CSS
Web Engineering - Introduction to CSS
 
html-css
html-csshtml-css
html-css
 
Web Programming-css.pptx
Web Programming-css.pptxWeb Programming-css.pptx
Web Programming-css.pptx
 
Web - CSS 1.pptx
Web - CSS 1.pptxWeb - CSS 1.pptx
Web - CSS 1.pptx
 
2_css.pptx
2_css.pptx2_css.pptx
2_css.pptx
 
2_css.pptx
2_css.pptx2_css.pptx
2_css.pptx
 
Css3
Css3Css3
Css3
 
CSS.pptx
CSS.pptxCSS.pptx
CSS.pptx
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
Cordova training - Day 2 Introduction to CSS 3
Cordova training - Day 2 Introduction to CSS 3Cordova training - Day 2 Introduction to CSS 3
Cordova training - Day 2 Introduction to CSS 3
 
Cascading Style Sheets
Cascading Style SheetsCascading Style Sheets
Cascading Style Sheets
 
Web Programming& Scripting Lab
Web Programming& Scripting LabWeb Programming& Scripting Lab
Web Programming& Scripting Lab
 
basics of css
basics of cssbasics of css
basics of css
 
CSS - Basics
CSS - BasicsCSS - Basics
CSS - Basics
 

More from Adeel Rasheed

More from Adeel Rasheed (20)

Multan to Sukkur Motorway (M5)
Multan to Sukkur Motorway (M5)Multan to Sukkur Motorway (M5)
Multan to Sukkur Motorway (M5)
 
Religious Conflict
Religious ConflictReligious Conflict
Religious Conflict
 
R Studio (Report)
R Studio (Report)R Studio (Report)
R Studio (Report)
 
History of computer (1st to 5th Generations)
History of computer (1st to 5th Generations)History of computer (1st to 5th Generations)
History of computer (1st to 5th Generations)
 
Zooming and Its Types
Zooming and Its TypesZooming and Its Types
Zooming and Its Types
 
User Interface & Its Types
User Interface & Its TypesUser Interface & Its Types
User Interface & Its Types
 
Questions About Android Application Development
Questions About Android Application DevelopmentQuestions About Android Application Development
Questions About Android Application Development
 
Human and Machine Learning
Human and Machine LearningHuman and Machine Learning
Human and Machine Learning
 
Connection Establishment & Flow and Congestion Control
Connection Establishment & Flow and Congestion ControlConnection Establishment & Flow and Congestion Control
Connection Establishment & Flow and Congestion Control
 
IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6IP Address - IPv4 & IPv6
IP Address - IPv4 & IPv6
 
Computer Crime
Computer CrimeComputer Crime
Computer Crime
 
Privacy and Security Information
Privacy and Security InformationPrivacy and Security Information
Privacy and Security Information
 
Code of Conduct - Code of Practice & Standards
Code of Conduct - Code of Practice & StandardsCode of Conduct - Code of Practice & Standards
Code of Conduct - Code of Practice & Standards
 
Self Adaptive Systems
Self Adaptive SystemsSelf Adaptive Systems
Self Adaptive Systems
 
Ethernet - LAN
Ethernet - LANEthernet - LAN
Ethernet - LAN
 
Synchronous and Asynchronous Transmission
Synchronous and Asynchronous TransmissionSynchronous and Asynchronous Transmission
Synchronous and Asynchronous Transmission
 
Classes and Objects in C#
Classes and Objects in C#Classes and Objects in C#
Classes and Objects in C#
 
Intel Microprocessors 8086 Documentation
Intel Microprocessors 8086 DocumentationIntel Microprocessors 8086 Documentation
Intel Microprocessors 8086 Documentation
 
Applications of Computer
Applications of ComputerApplications of Computer
Applications of Computer
 
Hysteresis Loop
Hysteresis LoopHysteresis Loop
Hysteresis Loop
 

Recently uploaded

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Recently uploaded (20)

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 

CSS Cascade Style Sheet

  • 1.
  • 2. Adeel Rasheed Custom Web Application Developer  https://chauhantricks.blogspot.com  https://www.fiverr.com/adeelrasheed
  • 3. What is CSS? CSS stands for Cascading Style Sheets CSS describes how HTML elements are to be displayed on screen CSS saves a lot of work. It can control the layout of multiple web pages all at once
  • 4. CSS Syntax  A CSS comprises of style rules that are interpreted by the browser and then applied to the corresponding elements in your document.  A style rule is made of three parts −  Selector − A selector is an HTML tag at which a style will be applied. This could be any tag like <h1> or <table> etc.  Property - A property is a type of attribute of HTML tag. Put simply, all the HTML attributes are converted into CSS properties. They could be color, border etc.  Value - Values are assigned to properties. For example, colorproperty can have value either red or #F1F1F1 etc.
  • 5. CSS Syntax selector { property: value } You can put CSS Style Rule Syntax as follows − Example p { color: red; text-align: center; }
  • 6. CSS Selectors  Selectors are one of the most important aspects of CSS as they are used to select elements on a web page so that they can be styled. 1-Element Type Selector  An element type selector matches every instance of the element in the document tree with the corresponding element type name. Example p { color: blue; } 2-Id Selectors The id selector is used to define style rules for a single or unique element. The id selector is defined with a '#' (hash) sign immediately followed by the id value. Example #error { color: red; } 3-Class Selector  The class selector selects elements with a specific class attribute.  To select elements with a specific class, write a period (.) character, followed by the name of the class. Example .center { text-align: center; color: red; }
  • 7. Inserting CSS Three Ways to Insert CSS  External style sheet  Internal style sheet  Inline style
  • 8. External Style Sheet  With an external style sheet, you can change the look of an entire website by changing just one file!  Each page must include a reference to the external style sheet file inside the <link> element. The <link> element goes inside the <head> section:  The style sheet file must be saved with a .css extension. Example  <head> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head>
  • 9. Internal Style Sheet  An internal style sheet may be used if one single page has a unique style.  Internal styles are defined within the <style> element, inside the <head> section of an HTML page: Example  <head> <style> body { background-color: linen; } h1 { color: maroon; margin-left: 40px; } </style> </head>
  • 10. Inline Styles  An inline style may be used to apply a unique style for a single element.  To use inline styles, add the style attribute to the relevant element. The style attribute can contain any CSS property.  The example below shows how to change the color and the left margin of a <h1> element: Example  <h1 style="color:blue;margin-left:30px;">This is a heading.</h1>
  • 11. Color property Colors in CSS are most often specified by:  a valid color name - like "red"  an RGB value - like "rgb(255, 0, 0)"  a HEX value - like "#ff0000"
  • 12. Background property Element Property Initial value 'background-attachment' scroll | fixed | inherit scroll 'background-color' <color> | transparent | inherit transparent 'background-image' <url> | none | inherit none 'background-position' [ [ <percentage> | <length> | left | center | right ] [ <percentage> |<length> | top | center | bottom ]? ] | [ [ left | center | right ] || [ top | center | bottom ] ] | inherit 0% 0% 'background-repeat' repeat | repeat-x | repeat-y | no-repeat | inherit repeat 'background' ['background-color' || 'background- image' || 'background-repeat' ||'background- attachment' ||'background-position'] | inherit see individual properties
  • 13. Border propertyElement Property Initial value 'border-color' [ <color> | see individual properties 'border-spacing' <length> <length>? 0 'border-style' None,solid,dotted,dashed,double,groove,ridge, inset,outset,hidden see individual properties 'border-top''border-right''border- bottom''border-left' [ <border-width> || <border-style> ||'border-top- color' ] see individual properties 'border-top-color' 'border-right- color''border-bottom-color' 'border-left- color' <color> the value of the 'color' property 'border-top-style' 'border-right- style''border-bottom-style' 'border-left- style' <border-style> None 'border-top-width' 'border-right- width''border-bottom-width' 'border-left- width' <border-width> medium 'border-width' length in px, pt or cm or it should be set to thin, medium or thick. see individual properties 'border' [ <border-width> || <border-style> ||'border-color' ] see individual properties
  • 14. Round Border property Element Property Initial value 'border-radius’ In pixels see individual properties 'border-top-right-radius'‘ 'border-top-left-radius‘‘ 'border-botttom-right-radius'‘ 'border-bottom-left-radius‘‘ In pixels see individual properties
  • 15. Outline Property  An outline is a line that is drawn around elements (outside the borders) to make the element "stand out".  Similar to border  Outline Sets all the outline properties in one declaration  outline-color Sets the color of an outline  outline-offset Specifies the space between an outline and the edge or border of an element  outline-styleSets the style of an outline  outline-widthSets the width of an outline
  • 16. Font property Element Property 'font-family' [[ <family-name> | <generic-family>] [, <family-name>| <generic-family>]* ] | inherit Example: font-family: "Times New Roman", Times, serif; 'font-size' <absolute-size> | <relative-size> |<length> | keywords: xx-small, x-small, small, medium, large, x-large, xx-large. size in pixel values (e.g. 12px, 16px, etc.) 'font-style' normal | italic | oblique | inherit 'font-variant' normal | small-caps | inherit 'font-weight' normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit 'font' [ [ 'font-style' || 'font-variant' || 'font-weight' ]? 'font-size' [ / 'line-height']? 'font-family' ] | caption | icon | menu | message-box | small-caption | status-bar | inherit 'height' <length> | <percentage> | auto |inherit 'letter-spacing' normal | <length> | inherit 'line-height' normal | <number> | <length> |<percentage> | inherit
  • 17. Text propertyElement Property Initial value 'text-align' left | right | center | justify | inherit a nameless value that acts as 'left' if 'direction' is 'ltr', 'right' if 'direction' is 'rtl' 'text-decoration' none | [ underline || overline || line-through || blink ] | inherit none 'text-indent' <length> | <percentage> | inherit 0 'text-transform' capitalize | uppercase | lowercase | none | inherit none 'text-align' left | right | center | justify | inherit a nameless value that acts as 'left' if 'direction' is 'ltr', 'right' if 'direction' is 'rtl'
  • 18. The BOX Model  The following diagram demonstrates how the margin, padding, and border CSS properties determines how much space an element can take on a web page.
  • 19. CSS Margins  The CSS margin properties are used to generate space around elements.  The margin properties set the size of the white space outside the border.  margin-top  margin-right  margin-bottom  margin-left  All the margin properties can have the following values:  auto - the browser calculates the margin  length - specifies a margin in px, pt, cm, etc.  % - specifies a margin in % of the width of the containing element  inherit - specifies that the margin should be inherited from the parent element
  • 20. CSS Margins Example  p { margin-top: 100px; margin-bottom: 100px; margin-right: 150px; margin-left: 80px; } Example shorthand  p { margin: 100px 150px 100px 80px; margin: 25px 50px 75px 100px; }
  • 21. CSS Margins  If the margin property has four values:  margin: 25px 50px 75px 100px;  top margin is 25px  right margin is 50px  bottom margin is 75px  left margin is 100px  If the margin property has three values:  margin: 25px 50px 75px;  top margin is 25px  right and left margins are 50px  bottom margin is 75px  If the margin property has two values:  margin: 25px 50px;  top and bottom margins are 25px  right and left margins are 50px  If the margin property has one value:  margin: 25px;  all four margins are 25px
  • 22. CSS Padding  The CSS padding properties are used to generate space around content.  The padding clears an area around the content (inside the border) of an element.  CSS has properties for specifying the padding for each side of an element:  padding-top  padding-right  padding-bottom  padding-left Example p { padding-top: 50px; padding-right: 30px; padding-bottom: 50px; padding-left: 80px; } Padding shorthand  p { padding: 50px 30px 50px 80px; }
  • 23. CSS Height and Width  The height and width properties are used to set the height and width of an element.  The height and width can be set to auto (this is default. Means that the browser calculates the height and width), or be specified in length values, like px, cm, etc., or in percent (%) of the containing block.  Example  div { height: 200px; width: 50%; background-color: powderblue; }
  • 24. CSS Height and Width  All CSS Dimension Properties  Height Sets the height of an element  max-height Sets the maximum height of an element  max-width Sets the maximum width of an element  min-height Sets the minimum height of an element  min-width Sets the minimum width of an element  Width Sets the width of an element
  • 25. CSS Links  With CSS, links can be styled in different ways. links can be styled differently depending on what state they are in. The four links states are: •a:link - a normal, unvisited link •a:visited - a link the user has visited •a:hover - a link when the user mouses over it •a:active - a link the moment it is clicked
  • 26. CSS Links Example /* unvisited link */ a:link { color: red; } /* visited link */ a:visited { color: green; } /* mouse over link */ a:hover { color: hotpink; } /* selected link */ a:active { color: blue; }
  • 27. CSS Tables Adding Borders to Tables  The CSS border property is the best way to define the borders for the tables.  The following example will set a black border for the <table>, <th>, and <td> elements. Example table, th, td { border: 1px solid black; }
  • 28. CSS Tables Adding Borders to Tables  The border-collapse CSS property selects a table's border model.  It can accept one of the two values collapse or separate.  The separated model is the default HTML table border model in which each Adjacent cells have their own distinct borders.  In the collapsed border model, adjacent table cells share borders. Example table { border-collapse: collapse; } table, th, td { border: 1px solid black; }
  • 29. CSS Tables  Striped Tables  For zebra-striped tables, use the nth-child() selector and add a background-color to all even (or odd) table rows: Example  tr:nth-child(even) {background-color: #f2f2f2}