SlideShare ist ein Scribd-Unternehmen logo
1 von 37
CSS
Fauzan Azmi (FZN)
What is CSS?
• 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
Three Layers of the Web
Styles Solved a Big
             Problem
• HTML was never intended to contain tags for
  formatting a document.
• HTML was intended to define the content of
  a document, like:
  o <h1>This is a heading</h1>
  o <p>This is a paragraph.</p>

• When tags like <font>, and color attributes
  were added to the HTML 3.2 specification, it
  started a nightmare for web developers.
Styles Solved a Big
           Problem
• Development of large web sites, where fonts
  and color information were added to every
  single page, became a long and expensive
  process.
• 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.
CSS Example
• A CSS declaration always ends with a
  semicolon, and declaration groups are
  surrounded by curly brackets:

p {color:red;text-align:center;}
CSS Comments
• Comments are used to explain your
  code, and may help you when you edit the
  source code at a later date. Comments are
  ignored by browsers.
• A CSS comment begins with "/*", and ends
  with "*/"
The id Selectors
• 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 "#".
• The style rule below will be applied to the element
  with id="para1":
     #para1
     {
             text-align:center;
             color:red;
     }
The class Selector
• 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 "."
• In the example below, all HTML elements with
  class="center" will be center-aligned:
           .center {text-align:center;}
You MUST not do !
• Do NOT start an ID name with a number! It
  will not work in Mozilla/Firefox.
• Do NOT start a class name with a number!
  This is only supported in Internet Explorer.
Three Ways to Insert CSS

• There are three ways of inserting a
  style sheet:
  o External style sheet
  o Internal style sheet
  o 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.
Examples
<head>
<link rel="stylesheet“
type="text/css" href="mystyle.css" />
</head>
Rules
• 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.
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
  <head>
  <style type="text/css">
  hr {color:sienna;}
  p {margin-left:20px;}
  body {background-
  image:url("images/back40.gif");}
  </style>
  </head>
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.
   <p style="color:sienna;margin-
   left:20px">This is a paragraph.</p>
Multiple Style Sheets
• If some properties have been set for the
  same selector in different style sheets, the
  values will be inherited from the more
  specific style sheet.
• What style will be used when there is more
  than one style specified for an HTML
  element?
Multiple Style Sheets
• Generally speaking we can say that all
  the styles will "cascade" into a new
  "virtual" style sheet by the following
  rules, where number four has the
  highest priority:
  o   Browser default
  o   External style sheet
  o   Internal style sheet (in the head section)
  o   Inline style (inside an HTML element)
CSS Background
• CSS background properties are used
  to define the background effects of
  an element.
• CSS properties used for background effects:
  o   background-color
  o   background-image
  o   background-repeat
  o   background-attachment
  o   background-position
Examples
h1 {background-color:#6495ed;}
body {background-image:url('paper.gif');}
body
{
    background-image:url('img_tree.png');
    background-repeat:no-repeat;
}
body {background:#ffffff
    url('img_tree.png') no-repeat right
    top;}
More Examples :
http://www.w3schools.com/css/css_background.asp
CSS Text
Property         Description
color            Sets the color of text
direction        Specifies the text direction/writing direction
letter-spacing   Increases or decreases the space between characters in a text
line-height      Sets the line height
text-align      Specifies the horizontal alignment of text
text-decoration Specifies the decoration added to text

text-indent      Specifies the indentation of the first line in a text-block
text-shadow      Specifies the shadow effect added to text
text-transform   Controls the capitalization of text
unicode-bidi
vertical-align   Sets the vertical alignment of an element
white-space      Specifies how white-space inside an element is handled
word-spacing     Increases or decreases the space between words in a text
CSS Font
font            Sets all the font properties in one
                declaration
font-family     Specifies the font family for text

font-size       Specifies the font size of text

font-style      Specifies the font style for text

font-variant    Specifies whether or not a text should
                be displayed in a small-caps font
font-weight     Specifies the weight of a font
CSS Links
• Links can be styled with any CSS property (e.g.
  color, font-family, background, etc.).
• Special for links are that they can be styled
  differently depending on what state they are in.
• The four links states are:
   o   a:link - a normal, unvisited link
   o   a:visited - a link the user has visited
   o   a:hover - a link when the user mouses over it
   o   a:active - a link the moment it is clicked
Examples
a:link {color:#FF0000;}     /* unvisited link */
a:visited {color:#00FF00;} /* visited link */
a:hover {color:#FF00FF;} /* mouse over link */
a:active {color:#0000FF;} /* selected link */

a:link {text-decoration:none;}
a:visited {text-decoration:none;}
a:hover {text-decoration:underline;}
a:active {text-decoration:underline;}
CSS Lists
• The CSS list properties allow you to:
   o Set different list item markers for ordered lists
   o Set different list item markers for unordered lists
   o Set an image as the list item marker
• Examples :
  ul.a   {list-style-type:       circle;}
  ul.b   {list-style-type:       square;}
  ol.c   {list-style-type:       upper-roman;}
  ol.d   {list-style-type:       lower-alpha;}
CSS List
Property              Description

list-style            Sets all the properties for a list in one
                      declaration

list-style-image      Specifies an image as the list-item marker


list-style-position   Specifies if the list-item markers should appear
                      inside or outside the content flow

list-style-type       Specifies the type of list-item marker
CSS Tables
•   Table Borders
•   Collapse Borders
•   Table Width and Height
•   Table Text Alignment
•   Table Padding
•   Table Color
Table Borders
• To specify table borders in CSS, use the border
  property.
• The example below specifies a black border for
  table, th, and td elements:

  table, th, td
  {
     border: 1px solid black;
  }
Collapse Borders
• The border-collapse property sets whether the table
  borders are collapsed into a single border or
  separated:
  table
  {
      border-collapse:collapse;
  }
  table,th, td
  {
      border: 1px solid black;
  }
Table Width and Height
• Width and height of a table is defined by the width
  and height properties.
• The example below sets the width of the table to
  100%, and the height of the th elements to 50px:
  table
  {
      width:100%;
  }
  th
  {
      height:50px;
  }
Table Text Alignment
• The text in a table is aligned with the text-align and
  vertical-align properties.
• The text-align property sets the horizontal
  alignment, like left, right, or center.
• Examples :
  td
  {
      height:50px;
      vertical-align:bottom;
  }
Table Padding
• To control the space between the border and
  content in a table, use the padding property on td
  and th elements:

  td
  {
       padding:15px;
  }
Table Color
• The example below specifies the color of the
  borders, and the text and background color of th
  elements:
  table, td, th
  {
      border:1px solid green;
  }
  th
  {
      background-color:green;
      color:white;
  }
Other Styles
• For more CSS Styles, you can visit here :
  http://www.w3schools.com/cssref/def
  ault.asp

Weitere ähnliche Inhalte

Was ist angesagt?

Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheetssmithaps4
 
Responsive web design with html5 and css3
Responsive web design with html5 and css3Responsive web design with html5 and css3
Responsive web design with html5 and css3Divya Tiwari
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSSSun Technlogies
 
Css Complete Notes
Css Complete NotesCss Complete Notes
Css Complete NotesEPAM Systems
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation Salman Memon
 
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)Webtech Learning
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheetvijayta
 
CSS tutorial chapter 2
CSS tutorial chapter 2CSS tutorial chapter 2
CSS tutorial chapter 2jeweltutin
 
CSS tutorial chapter 3
CSS tutorial chapter 3CSS tutorial chapter 3
CSS tutorial chapter 3jeweltutin
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Chris Poteet
 

Was ist angesagt? (19)

Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
Responsive web design with html5 and css3
Responsive web design with html5 and css3Responsive web design with html5 and css3
Responsive web design with html5 and css3
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
Cascading Style Sheets - CSS
Cascading Style Sheets - CSSCascading Style Sheets - CSS
Cascading Style Sheets - CSS
 
CSS
CSS CSS
CSS
 
Css
CssCss
Css
 
Css Complete Notes
Css Complete NotesCss Complete Notes
Css Complete Notes
 
Css
CssCss
Css
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
 
Complete Lecture on Css presentation
Complete Lecture on Css presentation Complete Lecture on Css presentation
Complete Lecture on Css presentation
 
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 Basics part One
CSS Basics part OneCSS Basics part One
CSS Basics part One
 
Cascading Style Sheet
Cascading Style SheetCascading Style Sheet
Cascading Style Sheet
 
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 notes
CSS notesCSS notes
CSS notes
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)Introduction to Cascading Style Sheets (CSS)
Introduction to Cascading Style Sheets (CSS)
 

Ähnlich wie Css (20)

CSS tutorial chapter 1
CSS tutorial chapter 1CSS tutorial chapter 1
CSS tutorial chapter 1
 
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
 
Css
CssCss
Css
 
Cascading style sheets
Cascading style sheetsCascading style sheets
Cascading style sheets
 
BITM3730 9-20.pptx
BITM3730 9-20.pptxBITM3730 9-20.pptx
BITM3730 9-20.pptx
 
Week11 Lecture: CSS
Week11 Lecture: CSSWeek11 Lecture: CSS
Week11 Lecture: CSS
 
Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)Cascading Style Sheet (CSS)
Cascading Style Sheet (CSS)
 
Css
CssCss
Css
 
CSS
CSSCSS
CSS
 
CSS - LinkedIn
CSS - LinkedInCSS - LinkedIn
CSS - LinkedIn
 
Css introduction
Css introductionCss introduction
Css introduction
 
Intro to html, css & sass
Intro to html, css & sassIntro to html, css & sass
Intro to html, css & sass
 
css.ppt
css.pptcss.ppt
css.ppt
 
Cascading Style Sheets By Mukesh
Cascading Style Sheets By MukeshCascading Style Sheets By Mukesh
Cascading Style Sheets By Mukesh
 
BITM3730Week4.pptx
BITM3730Week4.pptxBITM3730Week4.pptx
BITM3730Week4.pptx
 
Css
CssCss
Css
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
 
WEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptxWEB TECHNOLOGY Unit-2.pptx
WEB TECHNOLOGY Unit-2.pptx
 
6_CasCadingStylesSheetsCSS.ppt
6_CasCadingStylesSheetsCSS.ppt6_CasCadingStylesSheetsCSS.ppt
6_CasCadingStylesSheetsCSS.ppt
 

Mehr von Yudha Arif Budiman (20)

Operating system
Operating systemOperating system
Operating system
 
Persentasi Seminar Tugas Akhir
Persentasi Seminar Tugas AkhirPersentasi Seminar Tugas Akhir
Persentasi Seminar Tugas Akhir
 
Persentasi Seminar Kemajuan 1 Tugas Akhir
Persentasi Seminar Kemajuan 1 Tugas AkhirPersentasi Seminar Kemajuan 1 Tugas Akhir
Persentasi Seminar Kemajuan 1 Tugas Akhir
 
1. setting windows ac dan ad domain
1. setting windows ac dan ad domain1. setting windows ac dan ad domain
1. setting windows ac dan ad domain
 
9. kriptografi yudha
9. kriptografi   yudha9. kriptografi   yudha
9. kriptografi yudha
 
Biopori untuk kota bandung inspirator
Biopori untuk kota bandung inspiratorBiopori untuk kota bandung inspirator
Biopori untuk kota bandung inspirator
 
Tentang program sejuta biopori
Tentang program sejuta bioporiTentang program sejuta biopori
Tentang program sejuta biopori
 
Pembuatan lrb presentasi standar
Pembuatan lrb presentasi standarPembuatan lrb presentasi standar
Pembuatan lrb presentasi standar
 
Pemkot
PemkotPemkot
Pemkot
 
Persentasi 1 TA
Persentasi 1 TAPersentasi 1 TA
Persentasi 1 TA
 
Ead pertemuan-12
Ead pertemuan-12Ead pertemuan-12
Ead pertemuan-12
 
Ead pertemuan-8
Ead pertemuan-8Ead pertemuan-8
Ead pertemuan-8
 
Ead pertemuan-7
Ead pertemuan-7Ead pertemuan-7
Ead pertemuan-7
 
Ead pertemuan-5
Ead pertemuan-5Ead pertemuan-5
Ead pertemuan-5
 
Ead pertemuan-4
Ead pertemuan-4Ead pertemuan-4
Ead pertemuan-4
 
Ead pertemuan-3
Ead pertemuan-3Ead pertemuan-3
Ead pertemuan-3
 
Ead pertemuan-2
Ead pertemuan-2Ead pertemuan-2
Ead pertemuan-2
 
Ead pertemuan-1
Ead pertemuan-1Ead pertemuan-1
Ead pertemuan-1
 
Ead pertemuan-10
Ead pertemuan-10Ead pertemuan-10
Ead pertemuan-10
 
Apsi nas 2
Apsi nas  2Apsi nas  2
Apsi nas 2
 

Css

  • 2. What is CSS? • 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
  • 3. Three Layers of the Web
  • 4. Styles Solved a Big Problem • HTML was never intended to contain tags for formatting a document. • HTML was intended to define the content of a document, like: o <h1>This is a heading</h1> o <p>This is a paragraph.</p> • When tags like <font>, and color attributes were added to the HTML 3.2 specification, it started a nightmare for web developers.
  • 5. Styles Solved a Big Problem • Development of large web sites, where fonts and color information were added to every single page, became a long and expensive process. • 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.
  • 6.
  • 7. 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!
  • 8. 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.
  • 9. CSS Example • A CSS declaration always ends with a semicolon, and declaration groups are surrounded by curly brackets: p {color:red;text-align:center;}
  • 10. CSS Comments • Comments are used to explain your code, and may help you when you edit the source code at a later date. Comments are ignored by browsers. • A CSS comment begins with "/*", and ends with "*/"
  • 11. The id Selectors • 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 "#". • The style rule below will be applied to the element with id="para1": #para1 { text-align:center; color:red; }
  • 12. The class Selector • 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 "." • In the example below, all HTML elements with class="center" will be center-aligned: .center {text-align:center;}
  • 13. You MUST not do ! • Do NOT start an ID name with a number! It will not work in Mozilla/Firefox. • Do NOT start a class name with a number! This is only supported in Internet Explorer.
  • 14. Three Ways to Insert CSS • There are three ways of inserting a style sheet: o External style sheet o Internal style sheet o Inline style
  • 15. 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.
  • 17. Rules • 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.
  • 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 <head> <style type="text/css"> hr {color:sienna;} p {margin-left:20px;} body {background- image:url("images/back40.gif");} </style> </head>
  • 19. 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. <p style="color:sienna;margin- left:20px">This is a paragraph.</p>
  • 20. Multiple Style Sheets • If some properties have been set for the same selector in different style sheets, the values will be inherited from the more specific style sheet. • What style will be used when there is more than one style specified for an HTML element?
  • 21. Multiple Style Sheets • Generally speaking we can say that all the styles will "cascade" into a new "virtual" style sheet by the following rules, where number four has the highest priority: o Browser default o External style sheet o Internal style sheet (in the head section) o Inline style (inside an HTML element)
  • 22. CSS Background • CSS background properties are used to define the background effects of an element. • CSS properties used for background effects: o background-color o background-image o background-repeat o background-attachment o background-position
  • 23. Examples h1 {background-color:#6495ed;} body {background-image:url('paper.gif');} body { background-image:url('img_tree.png'); background-repeat:no-repeat; } body {background:#ffffff url('img_tree.png') no-repeat right top;} More Examples : http://www.w3schools.com/css/css_background.asp
  • 24. CSS Text Property Description color Sets the color of text direction Specifies the text direction/writing direction letter-spacing Increases or decreases the space between characters in a text line-height Sets the line height text-align Specifies the horizontal alignment of text text-decoration Specifies the decoration added to text text-indent Specifies the indentation of the first line in a text-block text-shadow Specifies the shadow effect added to text text-transform Controls the capitalization of text unicode-bidi vertical-align Sets the vertical alignment of an element white-space Specifies how white-space inside an element is handled word-spacing Increases or decreases the space between words in a text
  • 25. CSS Font font Sets all the font properties in one declaration font-family Specifies the font family for text font-size Specifies the font size of text font-style Specifies the font style for text font-variant Specifies whether or not a text should be displayed in a small-caps font font-weight Specifies the weight of a font
  • 26. CSS Links • Links can be styled with any CSS property (e.g. color, font-family, background, etc.). • Special for links are that they can be styled differently depending on what state they are in. • The four links states are: o a:link - a normal, unvisited link o a:visited - a link the user has visited o a:hover - a link when the user mouses over it o a:active - a link the moment it is clicked
  • 27. Examples a:link {color:#FF0000;} /* unvisited link */ a:visited {color:#00FF00;} /* visited link */ a:hover {color:#FF00FF;} /* mouse over link */ a:active {color:#0000FF;} /* selected link */ a:link {text-decoration:none;} a:visited {text-decoration:none;} a:hover {text-decoration:underline;} a:active {text-decoration:underline;}
  • 28. CSS Lists • The CSS list properties allow you to: o Set different list item markers for ordered lists o Set different list item markers for unordered lists o Set an image as the list item marker • Examples : ul.a {list-style-type: circle;} ul.b {list-style-type: square;} ol.c {list-style-type: upper-roman;} ol.d {list-style-type: lower-alpha;}
  • 29. CSS List Property Description list-style Sets all the properties for a list in one declaration list-style-image Specifies an image as the list-item marker list-style-position Specifies if the list-item markers should appear inside or outside the content flow list-style-type Specifies the type of list-item marker
  • 30. CSS Tables • Table Borders • Collapse Borders • Table Width and Height • Table Text Alignment • Table Padding • Table Color
  • 31. Table Borders • To specify table borders in CSS, use the border property. • The example below specifies a black border for table, th, and td elements: table, th, td { border: 1px solid black; }
  • 32. Collapse Borders • The border-collapse property sets whether the table borders are collapsed into a single border or separated: table { border-collapse:collapse; } table,th, td { border: 1px solid black; }
  • 33. Table Width and Height • Width and height of a table is defined by the width and height properties. • The example below sets the width of the table to 100%, and the height of the th elements to 50px: table { width:100%; } th { height:50px; }
  • 34. Table Text Alignment • The text in a table is aligned with the text-align and vertical-align properties. • The text-align property sets the horizontal alignment, like left, right, or center. • Examples : td { height:50px; vertical-align:bottom; }
  • 35. Table Padding • To control the space between the border and content in a table, use the padding property on td and th elements: td { padding:15px; }
  • 36. Table Color • The example below specifies the color of the borders, and the text and background color of th elements: table, td, th { border:1px solid green; } th { background-color:green; color:white; }
  • 37. Other Styles • For more CSS Styles, you can visit here : http://www.w3schools.com/cssref/def ault.asp