SlideShare a Scribd company logo
www.afghanhost.af - info@afghanhost.af
Instructor: Mohammad Rafi Haidari28-May-2014
CSS (Day 1)
 What is CSS
 CSS Syntax
 Selectors
 Ways to Insert CSS
 Backgrounds
CSS Introduction
 CSS stands for Cascading Style Sheets
 Styles define how to display HTML elements
 Styles were added to HTML 4.0 to solve a problem
 External Style Sheets can save a lot of work
 External Style Sheets are stored in CSS files
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 set consists of a selector and a declaration block:
 The selector points to the HTML element you want to style.
 The declaration block contains one or more declarations
separated by semicolons.
 Each declaration includes a property name and a value,
separated by a colon.
CSS Selectors
 CSS selectors allow you to select and manipulate HTML
element(s).
 CSS selectors are used to "find" (or select) HTML elements
based on their id, classes, types, attributes, values of
attributes and much more.
The element Selector
The element selector selects elements based on the element
name.
You can select all <p> elements on a page like this: (all <p>
elements will be center-aligned, with a red text color)
p
{
text-align:center;
CSS Selectors
The id Selector
The id selector uses the id attribute of an HTML tag to find the
specific element.
An id should be unique within a page, so you should use the id
selector when you want to find a single, unique element.
To find an element with a specific id, write a hash character, followed
by the id of the element.
The style rule below will be applied to the HTML element with
id="para1":
#para1
{
text-align:center;
color:red;
}
CSS Selectors
The class Selector
The class selector finds elements with the specific class.
The class selector uses the HTML class attribute.
To find elements with a specific class, write a period character,
followed by the name of the class:
In the example below, all HTML elements with class="center"
will be center-aligned:
.center
{
text-align:center;
color:red;
}
CSS Selectors
You 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:
p.center
{
text-align:center;
color:red;
}
Note: Do NOT start a class name with a number!
CSS Selectors
 Grouping Selectors
 In style sheets there are often elements with the same style:
h1
{
text-align:center;
color:red;
}
h2
{
text-align:center;
color:red;
}
p
{
text-align:center;
color:red;
}
To minimize the code, you can group selectors.
To group selectors, separate each selector with a
comma.
In the example below we have grouped the selectors
from the code leftside:
h1,h2,p
{
text-align:center;
color:red;
Ways to Insert CSS
There are three ways of inserting a style sheet:
 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. The <link> tag goes inside the head
section:
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
Ways to Insert CSS
Note: 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. An example of a style
sheet file is shown below:
hr {color:blue;}
p {margin-left:20px;}
body {background-image:url("images/background.gif");}
Note:Do not add a space between the property value and the
unit (such as margin-left:20 px). The correct way is: margin-
Ways to Insert CSS
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, like this:
<head>
<style>
hr {color:blue;}
p {margin-left:20px;}
body {background-image:url("images/background.gif");}
</style>
</head>
Ways to Insert CSS
Inline Styles
An inline style loses many of the advantages of style sheets by
mixing content with presentation. Use this method sparingly!
To use inline styles you use the style attribute in the relevant
tag. The style attribute can contain any CSS property. The
example shows how to change the color and the left margin of a
paragraph:
<p style="color:blue;margin-left:20px;">This is a
paragraph.</p>
CSS Background
CSS background properties are used to define the background
effects of an element.
CSS properties used for background effects:
 background-color
 background-image
 background-repeat
 background-position
CSS Background
Background Color
The background-color property specifies the background color
of an element.
The background color of a page is defined in the body selector:
body {background-color:#b0c4de;}
Background Image
The background-image property specifies an image to use as
the background of an element.
By default, the image is repeated so it covers the entire
element.
The background image for a page can be set like this:
CSS Background
Background Image - Repeat Horizontally or Vertically
By default, the background-image property repeats an image both
horizontally and vertically.
Some images should be repeated only horizontally or vertically, or they will
look strange, like this:
body
{
background-image:url("gradient.png");
}
If the image is repeated only horizontally (repeat-x), the background will look
better:
body
{
background-image:url("gradient.png");
background-repeat:repeat-x;
CSS Background
Set position and no-repeat
The position of the image is specified by the background-position property:
body
{
background-image:url("img_tree.png");
background-repeat:no-repeat;
background-position:right top;
}
Property Values
• left top
• left center
• left bottom
• right top
• right center
• right bottom
• center top
• center center
• center bottom
CSS_Day_ONE (W3schools)

More Related Content

PPTX
CSS_Day_Two (W3schools)
PPTX
CSS_Day_Three (W3schools)
PPT
CSS
PPT
How Cascading Style Sheets (CSS) Works
ODP
PPT
Cascading Style Sheets(CSS)
PPT
Introduction to Cascading Style Sheets (CSS)
CSS_Day_Two (W3schools)
CSS_Day_Three (W3schools)
CSS
How Cascading Style Sheets (CSS) Works
Cascading Style Sheets(CSS)
Introduction to Cascading Style Sheets (CSS)

What's hot (20)

PPTX
Cascading style sheets - CSS
PPT
CSS
PPTX
Cascading style sheet
PPT
CSS for Beginners
PPTX
Cascading Style Sheets - CSS
PPTX
Css types internal, external and inline (1)
PPTX
Beginners css tutorial for web designers
PPTX
Css ppt
PDF
Basic-CSS-tutorial
PDF
Web Design Course: CSS lecture 3
PPTX
CSS - Text Properties
PDF
Web Design Course: CSS lecture 4
PPTX
What is CSS?
PPT
Cascading Style Sheet
PPTX
CSS Basics
PPTX
CSS Cascade Style Sheet
PPT
PDF
cascadingstylesheets
Cascading style sheets - CSS
CSS
Cascading style sheet
CSS for Beginners
Cascading Style Sheets - CSS
Css types internal, external and inline (1)
Beginners css tutorial for web designers
Css ppt
Basic-CSS-tutorial
Web Design Course: CSS lecture 3
CSS - Text Properties
Web Design Course: CSS lecture 4
What is CSS?
Cascading Style Sheet
CSS Basics
CSS Cascade Style Sheet
cascadingstylesheets
Ad

Viewers also liked (16)

PDF
Bootstrap day2
PPTX
Records of the olympic field games (6)
PPTX
Women in science
PDF
Final Project
PPTX
HTML_Day_Two(W3Schools)
PDF
ნიცშე 'ასე იტყოდა ზარატუსტრა'
PPTX
New organic clothes image
PPTX
Introduce my self
PDF
Onet eng
PDF
PDF
Lose weight dieting success guaranteed
PDF
งานK7 (1)
DOC
Лауреати обласної літературної премії імені Василя Симоненка (До 80-річчя від...
PPTX
PowePoint
PPTX
Historia juegos olimpicos59
PPTX
Olympic games 22
Bootstrap day2
Records of the olympic field games (6)
Women in science
Final Project
HTML_Day_Two(W3Schools)
ნიცშე 'ასე იტყოდა ზარატუსტრა'
New organic clothes image
Introduce my self
Onet eng
Lose weight dieting success guaranteed
งานK7 (1)
Лауреати обласної літературної премії імені Василя Симоненка (До 80-річчя від...
PowePoint
Historia juegos olimpicos59
Olympic games 22
Ad

Similar to CSS_Day_ONE (W3schools) (20)

PPTX
chitra
DOC
Css introduction
PPTX
Introduction to CSS
DOC
Css introduction
PDF
TUTORIAL DE CSS 2.0
PPT
working with internet technologies using CSS
PPTX
Introduction of css
PDF
Css tutorial
PPTX
Lecture-6.pptx
PPT
Chapter 4a cascade style sheet css
PPTX
CSS Basics part One
PPTX
CSS tutorial chapter 1
PPTX
HTML to CSS Basics Exer 2.pptx
PPT
Introduction to css by programmerblog.net
PPT
Cascading Style Sheet
PDF
Introduction to css
PPTX
Cascading style sheet, CSS Box model, Table in CSS
PPTX
Casecading Style Sheets for Hyper Text Transfer Protocol.pptx
PPTX
PPTX
chitra
Css introduction
Introduction to CSS
Css introduction
TUTORIAL DE CSS 2.0
working with internet technologies using CSS
Introduction of css
Css tutorial
Lecture-6.pptx
Chapter 4a cascade style sheet css
CSS Basics part One
CSS tutorial chapter 1
HTML to CSS Basics Exer 2.pptx
Introduction to css by programmerblog.net
Cascading Style Sheet
Introduction to css
Cascading style sheet, CSS Box model, Table in CSS
Casecading Style Sheets for Hyper Text Transfer Protocol.pptx

More from Rafi Haidari (13)

PPTX
Lecture9 web design and development
PPTX
Lecture8 web design and development
PPTX
Lecture7 web design and development
PPTX
Lecture6 web design and development
PPTX
Lecture5 web design and development
PPTX
Lecture4 web design and development
PPTX
Lecture3 web design and development
PPTX
Lecture2 web design and development
PPTX
Lecture1 Web Design and Development
PDF
Bootstrap day3
PDF
Bootstrap day1
PPTX
Html_Day_One (W3Schools)
PPTX
Html_Day_Three(W3Schools)
Lecture9 web design and development
Lecture8 web design and development
Lecture7 web design and development
Lecture6 web design and development
Lecture5 web design and development
Lecture4 web design and development
Lecture3 web design and development
Lecture2 web design and development
Lecture1 Web Design and Development
Bootstrap day3
Bootstrap day1
Html_Day_One (W3Schools)
Html_Day_Three(W3Schools)

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
KodekX | Application Modernization Development
PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Modernizing your data center with Dell and AMD
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Approach and Philosophy of On baking technology
Spectral efficient network and resource selection model in 5G networks
Building Integrated photovoltaic BIPV_UPV.pdf
Review of recent advances in non-invasive hemoglobin estimation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The AUB Centre for AI in Media Proposal.docx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
NewMind AI Monthly Chronicles - July 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
KodekX | Application Modernization Development
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Chapter 3 Spatial Domain Image Processing.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
A Presentation on Artificial Intelligence
Modernizing your data center with Dell and AMD
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Approach and Philosophy of On baking technology

CSS_Day_ONE (W3schools)

  • 1. www.afghanhost.af - info@afghanhost.af Instructor: Mohammad Rafi Haidari28-May-2014 CSS (Day 1)  What is CSS  CSS Syntax  Selectors  Ways to Insert CSS  Backgrounds
  • 2. CSS Introduction  CSS stands for Cascading Style Sheets  Styles define how to display HTML elements  Styles were added to HTML 4.0 to solve a problem  External Style Sheets can save a lot of work  External Style Sheets are stored in CSS files 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!
  • 3. CSS Syntax  A CSS rule set consists of a selector and a declaration block:  The selector points to the HTML element you want to style.  The declaration block contains one or more declarations separated by semicolons.  Each declaration includes a property name and a value, separated by a colon.
  • 4. CSS Selectors  CSS selectors allow you to select and manipulate HTML element(s).  CSS selectors are used to "find" (or select) HTML elements based on their id, classes, types, attributes, values of attributes and much more. The element Selector The element selector selects elements based on the element name. You can select all <p> elements on a page like this: (all <p> elements will be center-aligned, with a red text color) p { text-align:center;
  • 5. CSS Selectors The id Selector The id selector uses the id attribute of an HTML tag to find the specific element. An id should be unique within a page, so you should use the id selector when you want to find a single, unique element. To find an element with a specific id, write a hash character, followed by the id of the element. The style rule below will be applied to the HTML element with id="para1": #para1 { text-align:center; color:red; }
  • 6. CSS Selectors The class Selector The class selector finds elements with the specific class. The class selector uses the HTML class attribute. To find elements with a specific class, write a period character, followed by the name of the class: In the example below, all HTML elements with class="center" will be center-aligned: .center { text-align:center; color:red; }
  • 7. CSS Selectors You 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: p.center { text-align:center; color:red; } Note: Do NOT start a class name with a number!
  • 8. CSS Selectors  Grouping Selectors  In style sheets there are often elements with the same style: h1 { text-align:center; color:red; } h2 { text-align:center; color:red; } p { text-align:center; color:red; } To minimize the code, you can group selectors. To group selectors, separate each selector with a comma. In the example below we have grouped the selectors from the code leftside: h1,h2,p { text-align:center; color:red;
  • 9. Ways to Insert CSS There are three ways of inserting a style sheet:  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. The <link> tag goes inside the head section: <head> <link rel="stylesheet" type="text/css" href="mystyle.css"> </head>
  • 10. Ways to Insert CSS Note: 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. An example of a style sheet file is shown below: hr {color:blue;} p {margin-left:20px;} body {background-image:url("images/background.gif");} Note:Do not add a space between the property value and the unit (such as margin-left:20 px). The correct way is: margin-
  • 11. Ways to Insert CSS 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, like this: <head> <style> hr {color:blue;} p {margin-left:20px;} body {background-image:url("images/background.gif");} </style> </head>
  • 12. Ways to Insert CSS Inline Styles An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly! To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph: <p style="color:blue;margin-left:20px;">This is a paragraph.</p>
  • 13. CSS Background CSS background properties are used to define the background effects of an element. CSS properties used for background effects:  background-color  background-image  background-repeat  background-position
  • 14. CSS Background Background Color The background-color property specifies the background color of an element. The background color of a page is defined in the body selector: body {background-color:#b0c4de;} Background Image The background-image property specifies an image to use as the background of an element. By default, the image is repeated so it covers the entire element. The background image for a page can be set like this:
  • 15. CSS Background Background Image - Repeat Horizontally or Vertically By default, the background-image property repeats an image both horizontally and vertically. Some images should be repeated only horizontally or vertically, or they will look strange, like this: body { background-image:url("gradient.png"); } If the image is repeated only horizontally (repeat-x), the background will look better: body { background-image:url("gradient.png"); background-repeat:repeat-x;
  • 16. CSS Background Set position and no-repeat The position of the image is specified by the background-position property: body { background-image:url("img_tree.png"); background-repeat:no-repeat; background-position:right top; } Property Values • left top • left center • left bottom • right top • right center • right bottom • center top • center center • center bottom