SlideShare uma empresa Scribd logo
1 de 13
Baixar para ler offline
Cascading Style Sheets
              --CAS 483--
What is a Style Sheet?
 “A set of statements that specify the
 presentation of a document”
 In other words, a style sheet defines how to
 display an HTML document
 External style sheets can be applied to a
 number of HTML documents
   CSS gives a “look” to your site
   Style sheets in action
Why use CSS?
 Enable you to change the appearance and
 layout of your entire site by editing only one
 file
 Improve site accessibility
CSS Syntax
 Generic CSS syntax:
  selector {property: value;}
  For example, we can change background color:
    body { background-color: black; }

 CSS Comments
  Comments are surrounded by /* and */
    /* This is a CSS comment */
CSS Syntax
 Class selector
   Can define different style types for the same
   HTML element
     p.center { text-align: center; }
     p.right { text-align: right; }
     <p class=“center”>…</p>
   Or, we can define a style for all HTML elements
     .center { text-align: center; }
     <h1 class=“center”>…</p>
DIV and SPAN Tags
 Div tag adds block-level structure/formatting
 <div class=“style_name”>…</div>
 <div style=“property:value”>…</div>
 <div align=“center|right|left”>…</div>

 Span tag adds inline-level
 structure/formatting
 <span class=“style_name”>…</div>
 <span style=“property:value”>…</div>
Applying a Style Sheet
 External Style Sheet
   Can be applied to a number of HTML pages
   To link a style sheet to an HTML document:
   <head>
   <link rel="stylesheet" type="text/css"
    href="mystyle.css" />
   </head>

 Internal Style Sheet
   Applied to only one HTML document
   <head><style>…</style></head>
What can CSS be used for?
 Page layout
   Positioning, etc.
 Font and text properties
   Indent the first line of a paragraph
 Color and background properties
 Box properties
   Margins, borders, dimensions
Examples
  Modify the appearance           Create new styles:
  of an HTML element:           .mainbox {
                                   font-size: 85%;
body {
                                   width: 530px;
   font-family: "Tahoma",
   "Arial", sans-serif;            border: 1px solid #c0c0c0;
   font-size: 100%;                vertical-align: top;
   color: #000000;                 padding: 2px;
   background-color: #ffffff;   }
}                               .txtlink {
h1 {                               color: #990000;
   font-size: 110%;                background-color:
   margin-bottom: 6px;             #ffffff;
}                               }
A Few Hints
 Text styles for the body are not inherited by
 text in a table
 To center a table:
 .center table {
    margin-left: auto; margin-right: auto; text-align: left;
 }

 To add a border around an image:
 img.textpic-l {
    border: 1px solid black; margin: 4px; float: left;
 }

   http://www.cae.wisc.edu/~kahnj/tcc/
Creating Links with CSS
 CSS can be used to create link effects
 .txtlink {
      color: #990000;
    background-color: #ffffff;
 }
 a.txtlink:link {
      text-decoration: underline;
 }
 a.txtlink:visited {
      text-decoration: underline;
 }
 a.txtlink:hover {
      color: #ffcc00;
      background-color: #ffffff;
    text-decoration: none;
 }
Where to go from here
 Try out CSS:
   Create a simple HTML page
    Include the link tag in order to apply the style sheet
    Include a number of HTML elements (headers, etc)
   Create a style sheet (<file_name>.css)
    Use the style sheet to modify the appearance of
    several HTML elements
    Create your own styles
   Modify the style sheet and reload your page
 Add a style sheet to your project
Resources
 CSS2 Specification
  http://www.w3.org/TR/REC-CSS2/
 Guide to CSS
  http://www.htmlhelp.com/reference/css/
 CSS Tutorial
  http://www.w3schools.com/css/
 CSS Layout Techniques
  http://glish.com/css/

Mais conteúdo relacionado

Mais procurados (16)

CSS_Day_Three (W3schools)
CSS_Day_Three (W3schools)CSS_Day_Three (W3schools)
CSS_Day_Three (W3schools)
 
LIS3353 SP12 Week 13
LIS3353 SP12 Week 13LIS3353 SP12 Week 13
LIS3353 SP12 Week 13
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
Cascading style-sheet-
Cascading style-sheet-Cascading style-sheet-
Cascading style-sheet-
 
Css
CssCss
Css
 
CSS Introduction
CSS IntroductionCSS Introduction
CSS Introduction
 
Web programming css
Web programming cssWeb programming css
Web programming css
 
CSS
CSSCSS
CSS
 
Cascstylesheets
CascstylesheetsCascstylesheets
Cascstylesheets
 
CSS
CSSCSS
CSS
 
PHP - Introduction to PHP CSS
PHP -  Introduction to PHP CSSPHP -  Introduction to PHP CSS
PHP - Introduction to PHP CSS
 
Fundamental CSS3
Fundamental CSS3Fundamental CSS3
Fundamental CSS3
 
CSS Boc model
CSS Boc model CSS Boc model
CSS Boc model
 
Class 2: CSS Selectors, Classes & Ids
Class 2: CSS Selectors, Classes & IdsClass 2: CSS Selectors, Classes & Ids
Class 2: CSS Selectors, Classes & Ids
 
Css presentation introdution with sample basic projects
Css presentation introdution with sample basic projectsCss presentation introdution with sample basic projects
Css presentation introdution with sample basic projects
 
Introduction to HTML and CSS
Introduction to HTML and CSSIntroduction to HTML and CSS
Introduction to HTML and CSS
 

Semelhante a cascadingstylesheets

Semelhante a cascadingstylesheets (20)

Introduction to css by programmerblog.net
Introduction to css by programmerblog.netIntroduction to css by programmerblog.net
Introduction to css by programmerblog.net
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
css-ppt.pdf
css-ppt.pdfcss-ppt.pdf
css-ppt.pdf
 
html-css
html-csshtml-css
html-css
 
CSS
CSSCSS
CSS
 
Css introduction
Css  introductionCss  introduction
Css introduction
 
TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0TUTORIAL DE CSS 2.0
TUTORIAL DE CSS 2.0
 
Chapter 4a cascade style sheet css
Chapter 4a cascade style sheet cssChapter 4a cascade style sheet css
Chapter 4a cascade style sheet css
 
Css tutorial
Css tutorialCss tutorial
Css tutorial
 
Css
CssCss
Css
 
Css
CssCss
Css
 
CSS
CSSCSS
CSS
 
waxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.ppt
waxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.pptwaxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.ppt
waxaada canshuurahaiyosiyaaddaguudeexamarwaaardaydaDAALBADAN.ppt
 
css1.ppt
css1.pptcss1.ppt
css1.ppt
 
Css
CssCss
Css
 
Css introduction
Css introductionCss introduction
Css introduction
 
David Weliver
David WeliverDavid Weliver
David Weliver
 
WT CSS
WT  CSSWT  CSS
WT CSS
 
DW_lesson2.ppt
DW_lesson2.pptDW_lesson2.ppt
DW_lesson2.ppt
 
DW_lesson2.ppt
DW_lesson2.pptDW_lesson2.ppt
DW_lesson2.ppt
 

Mais de tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 

Mais de tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 

Último

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Último (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

cascadingstylesheets

  • 2. What is a Style Sheet? “A set of statements that specify the presentation of a document” In other words, a style sheet defines how to display an HTML document External style sheets can be applied to a number of HTML documents CSS gives a “look” to your site Style sheets in action
  • 3. Why use CSS? Enable you to change the appearance and layout of your entire site by editing only one file Improve site accessibility
  • 4. CSS Syntax Generic CSS syntax: selector {property: value;} For example, we can change background color: body { background-color: black; } CSS Comments Comments are surrounded by /* and */ /* This is a CSS comment */
  • 5. CSS Syntax Class selector Can define different style types for the same HTML element p.center { text-align: center; } p.right { text-align: right; } <p class=“center”>…</p> Or, we can define a style for all HTML elements .center { text-align: center; } <h1 class=“center”>…</p>
  • 6. DIV and SPAN Tags Div tag adds block-level structure/formatting <div class=“style_name”>…</div> <div style=“property:value”>…</div> <div align=“center|right|left”>…</div> Span tag adds inline-level structure/formatting <span class=“style_name”>…</div> <span style=“property:value”>…</div>
  • 7. Applying a Style Sheet External Style Sheet Can be applied to a number of HTML pages To link a style sheet to an HTML document: <head> <link rel="stylesheet" type="text/css" href="mystyle.css" /> </head> Internal Style Sheet Applied to only one HTML document <head><style>…</style></head>
  • 8. What can CSS be used for? Page layout Positioning, etc. Font and text properties Indent the first line of a paragraph Color and background properties Box properties Margins, borders, dimensions
  • 9. Examples Modify the appearance Create new styles: of an HTML element: .mainbox { font-size: 85%; body { width: 530px; font-family: "Tahoma", "Arial", sans-serif; border: 1px solid #c0c0c0; font-size: 100%; vertical-align: top; color: #000000; padding: 2px; background-color: #ffffff; } } .txtlink { h1 { color: #990000; font-size: 110%; background-color: margin-bottom: 6px; #ffffff; } }
  • 10. A Few Hints Text styles for the body are not inherited by text in a table To center a table: .center table { margin-left: auto; margin-right: auto; text-align: left; } To add a border around an image: img.textpic-l { border: 1px solid black; margin: 4px; float: left; } http://www.cae.wisc.edu/~kahnj/tcc/
  • 11. Creating Links with CSS CSS can be used to create link effects .txtlink { color: #990000; background-color: #ffffff; } a.txtlink:link { text-decoration: underline; } a.txtlink:visited { text-decoration: underline; } a.txtlink:hover { color: #ffcc00; background-color: #ffffff; text-decoration: none; }
  • 12. Where to go from here Try out CSS: Create a simple HTML page Include the link tag in order to apply the style sheet Include a number of HTML elements (headers, etc) Create a style sheet (<file_name>.css) Use the style sheet to modify the appearance of several HTML elements Create your own styles Modify the style sheet and reload your page Add a style sheet to your project
  • 13. Resources CSS2 Specification http://www.w3.org/TR/REC-CSS2/ Guide to CSS http://www.htmlhelp.com/reference/css/ CSS Tutorial http://www.w3schools.com/css/ CSS Layout Techniques http://glish.com/css/