Escolar Documentos
Profissional Documentos
Cultura Documentos
Todays Topic
Using Cascading Style Sheets Create style sheets that configure common color and text properties Apply inline styles Use embedded style sheets Use external style sheets Create CSS class and id selectors Q/A
Visit http://www.csszengarden.com
Style Sheets
used for years in Desktop Publishing apply typographical styles and spacing to printed media
CSS
provides the functionality of style sheets (and much more) for web developers a flexible, cross-platform, standards-based language developed by the W3C.
CSS Advantages
Greater typography and page layout control Style is separate from structure Styles can be stored in a separate document and linked to from the web page Potentially smaller documents Easier site maintenance
Inline Styles
Configured in the body of the Web page Use the style attribute of an HTML tag; Apply only to the specific element
Embedded Styles
Configured in the header section of a Web page. Use the HTML <style> element; Apply to the entire Web page document
External Styles
Configured in a separate text file with .css file extension The HTML <link /> element in the header section of a Web page associates it with the .css file
CSS Syntax
Style sheets are composed of "Rules" that describe the styling to be applied. Each Rule contains a Selector and a Declaration
CSS Style Rule Selector: HTML element, class name, an id name CSS Style Rule Declaration: Property + Value
background-color color font-family font-size font-style font-weight line-height margin, margin-left, margin-right text-align text-decoration width
Computer monitors display color as intensities of red, green, and blue light; RGB Color The values of red, green, and blue vary from 0 to 255. Hexadecimal numbers (base 16) represent these color values. Hexadecimal color values
# is used to indicate a hexadecimal value Hex value pairs range from 00 to FF Three hex value pairs describe an RGB color
CSS Syntax p { color: red; } p { color: #FF0000; } p { color: #F00; } p { color: rgb(255, 0, 0); }
Inline CSS
Configured in the body of the Web page Use the style attribute of an HTML tag Apply only to the specific element
Example: configure red color text in an <h1> element: <h1 style="color:#ff0000">Heading text is red</h1>
Configured in the header section of a Web page. Use the HTML <style> element Apply to the entire Web page document Style declarations are contained between the opening and closing <style> tags Example: Configure a Web page with white text on a black background
The body selector sets the global style rules for the entire page. These global rules are overridden for <h1> and <h2> elements by the h1 and h2 style rules.
<style type="text/css"> body { background-color: #E6E6FA; color: #191970;} h1 { background-color: #191970; color: #E6E6FA;} h2 { background-color: #AEAED4; color: #191970;} </style>
Questions
Cascading Style Sheet rules are comprised of: a. Selectors and Declarations b. Properties and Declarations c. Selectors and Attributes When CSS is coded in the body of the d. None of the above web page as an attribute of an HTML tag it is called ________. a. Embedded To associate an external style sheet with b. Inline a web page, code: c. External a. a link element in the body section of d Imported the web page b. a link element in the head section of the web page c. a style element in the body section of the web page d. a style element in the head section of the web page
font-weight
Configures the boldness of text Configures text to an italic style Configures the size of the text Configures the font typeface of the text
font-style
font-size
font-family
Accessibility Recommendation:
Use em or percentage font sizes these can be easily enlarged in all browsers by users
Not everyone has the same fonts installed in their computer Configure a list of fonts and include a generic family name
<style type="text/css"> body { background-color: #E6E6FA; color: #191970; font-family: Arial, Verdana, sans-serif; } h1 { background-color: #191970; color: #E6E6FA; line-height: 200%; font-family: Georgia, "Times New Roman", serif; } h2 { background-color: #AEAED4; color: #191970; font-family: Georgia, "Times New Roman", serif; text-align: center } p {font-size: .90em; text-indent: 3em; } ul {font-weight: bold; } </style>
CSS Selectors
class Selector
Apply a CSS rule to a certain "class" of elements on a Web page Does not associate the style to a particular HTML element
id Selector
The sample creates an id called new with red, large, italic text.
<style type="text/css"> .nav {font-weight: bold; font-size: 1.25 em;} .feature { color: #ff0000; } #footer {color: #333333; font-size: .75em; font-style: italic;} </style> ... <div class=nav><a href=index.html>Home</a> <a href=services.html>Services</a> <a href=contact.html>Contact</a></p> <li class=feature>Usability Studies</li> <li class=feature>Search Engine Optimization</li> <div id=footer>Copy right © 2011 Your Name Here</p>
Specify an element within the context of its container (parent) element AKA descendent selector Example figures a green text color only for anchor tags located within the footer id Advantage of contextual selectors:
Reduce the number of classes and ids you need to apply in the HTML
A block-level element Purpose: configure a specially formatted division or area of a Web page
There is a line break before and after the division. Can contain other block-level and inline elements
Useful to define an area that will contain other block-level tags (such as paragraphs or spans) within it.
Configure a page footer area Embedded CSS: <style type="text/css"> .footer { font-size: small; text-align: center; } </style>
Configure a specially formatted area displayed in-line with other elements, such as within a paragraph.
Embedded CSS:
<style type="text/css"> .companyname { font-weight: bold; font-family: Georgia, "Times New Roman", serif; font-size: 1.25em; } </style>
HTML:
<p>Your needs are important to us at <span class=companyname">Acme Web Design</span>. We will work with you to build your Web site.</p>
<style type="text/css"> .companyname {font=weight: bold; font-family: Georgia, Times New Roman, serif; font-size: 1.25em; </style> ... <p><span class=companyname>Trillium Media Design</span> will bring
CSS style rules are contained in a text file separate from the HTML documents. The External Style Sheet text file:
extension ".css" contains only style rules does not contain any HTML tags
Multiple web pages can associate with the same external style sheet file.
site.css
index.htm
background-color:#E6E6FA; color:#000000; font-family:Arial, sans-serif; font-size:90%;
body {
clients.htm
about.htm
Etc
associates the external style sheet file with the web page.
Example:
To link to the external style sheet called color.css, the HTML code placed in the header section is:
<link rel="stylesheet" href="color.css" type="text/css" />
Questions
Select the code below that uses CSS to configure a id named footer that configures small, italic text. a. #footer { font-size: small; font-weight: italic;} b. .footer{ font-size: small; font-style: italic;} c. .footer { font-size: small; font-style: italic;} d. #footer { font-size: small; font-style: italic;} Select the code below that uses CSS to configure a background color of #eaeaea for a web page. a. body {background-color:#eaeaea; } b. document {background-page:#eaeaea; } c. body {bgcolor:#eaeaea; } d. None of the above
To apply a style to a certain group of elements on a web page, configure a CSS _____________. a. group b. id c. class d. None of the above