1 / 41

HTML Tutorials 3 & 4: Working With CSS

CIS 1315. HTML Tutorials 3 & 4: Working With CSS. CSS Basics. Style Rules Determines Style Characteristics for an HTML Element Selector Determines Element to Which Rule is Applied Declaration Details the Exact Property Values Property Quality or Characteristic (e.g., Color) Value

talasi
Download Presentation

HTML Tutorials 3 & 4: Working With CSS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 1315 HTMLTutorials 3 & 4: Working With CSS

  2. CSS Basics • Style Rules • Determines Style Characteristics for an HTML Element • Selector • Determines Element to Which Rule is Applied • Declaration • Details the Exact Property Values • Property • Quality or Characteristic (e.g., Color) • Value • Specification of Property (e.g., Blue) • Style Sheet • Set of Style Rules

  3. CSS Basics • Style Rule Syntax

  4. Combining CSS & HTML • Inline • Modify the Appearance of a Particular Element • Style Attribute • Embedded • Applied To An Entire Document • Redefines All Occurrences of a Particular Element • Uses <style>…</style> in <head> • Linked • External File of Declarations Available to an Entire Site • ASCII File with an Extension of .css

  5. Inline Style • Defines a Style for a Single Element • Generally Used to Override a Style Set at a Higher Level • Only Affects One Instance of an Element • Syntax • <tag style=“property:value1; property:value2;”> <h1 style=“color:green; font-family:sans-serif;”> <b style=“color:yellow; background-color:green;”>

  6. Embedded Style • Always Contained in the <head> • Generally Used to Override a Style Set at a Higher Level • Only Affects the Document in Which it Resides • Syntax • selector {declarations} <style type=“text/css”> h1 {color:green; font-family:sans-serif;} b {color:yellow; background-color:green;} </style>

  7. Linked Style • External Style Sheet • Always Contained in the <head> • Text Document that Contains Style Rules • Allows Specification of Rules for Multiple Documents • Does Not Contain HTML Code • Syntax <link rel=“stylesheet” href=“master.css”>

  8. Inheritance • Parent • Element that Contains Another Element • Child • Element within Another Element • Inheritance • CSS Rules Inherit from Parent to Child Elements • Based on Hierarchical Structure of Documents

  9. Basic Selection • Type Selectors • Selector Determines Element to which Declaration is Applied • Style Sheet Examples: h2 {color: red;} p {font-size: 10 pt;}

  10. Basic Selection • Grouping Selectors • Set the Same Declaration for Multiple Selectors • Syntax: h1 {color: red;} h2 {color: red;} or h1, h2 {color: red;}

  11. Basic Selection • Combining Declarations • Multiple Declarations May be Stated for Same Selector • Syntax: p {color: blue;} p {font-size: 12pt;} or p {color: blue; font-size: 12pt;}

  12. Basic Selection • Descendant Selector • AKA Contextual Selectors • Based on Hierarchical Structure of Elements in Document • Syntax: b i {color: #336699; background-color: #000000;} • Does Not Apply to i b

  13. Advanced Selection • id Attribute Selector • Applied to Only ONEUnique Element in a Document • Core Attribute that can be Applied to Any HTML Element • Syntax: <p id=“preface”>This is a unique paragraph that is the preface of the document</p>

  14. Advanced Selection • class Attribute Selector • Enables Application of Rule to Selected Element(s) • Core Attribute that can be Applied to Any HTML Element • Syntax: <p class=“quote”>Text in red with a 30 pixel margin</p> • May be Restricted to a Specific Element Type h1.quote {color: red; margin: 30px;}

  15. Advanced Selection • <div>…</div> • Block Level Element • Used to Contain Other HTML Elements • Displayed Discretely from the Rest of the Document • Paragraph Breaks Added Before and After <div> Contents • <span>…</span> • Inline Element • Used to Contain Other HTML Elements • Used within Text Blocks

  16. Advanced Selection • Pseudo-Class Selectors • Select Elements Based on Characteristics Other Than Name • Link Pseudo-Classes • :link • Allow Modification of Style Characteristics for Unvisited Links :link {color: green;} • :visited • Allow Modification of Style Characteristics for Visited Links :visited {color: green;}

  17. Advanced Selection • Pseudo-Class Selectors • Dynamic Pseudo-Classes • Apply Styles to an Element Based on User’s Actions • :hover • Applies Style When User Mouses Over Element • :active • Applies Style When User Activates Element • :focus • Applies Style When Element is Accepting User Input

  18. Advanced Selection • Pseudo-Elements Selectors • Modify Aspects of Document Not Classified by Elements • :first-letter • Apply Style Rules to the First Letter of Any Block-level Element • Initial Capitals • Drop Capitals

  19. Advanced Selection • Pseudo-Element Selectors • :first-letter

  20. Advanced Selection • Pseudo-Element Selectors • :first-line • Apply Style Rules to the First Line of Any Block-level Element

  21. Visual Formatting Model • Three Element Display Type Categories • Block (e.g., Paragraphs) • Contain Inline Boxes that Contain Element Content • Inline • Contain Content within the Block-level Elements • Do not Form New Blocks of Content • List-item • Creates Surrounding Container and List-item Inline Boxes • display: block | inline | list-item | none

  22. Box Model • Describes Rectangular Boxes that Contain Content • Each Block-level Element is Displayed as a Box • Each Content Box can have Margins, Borders, & Padding

  23. Margin Properties • margin: # | % • Shorthand Property Sets All Four Individual Margins

  24. Margin Properties • margin-left | margin-right | margin-top | margin-bottom: # | % • Negative margins can be set to achieve special effects

  25. Padding Properties • padding: # | % • Shorthand Property Sets All Four Individual Paddings • Same Format as Margin • padding-left | padding-right | padding-top | padding-bottom: # | %

  26. Border Properties • border: style width color • Shorthand Property Sets All Four Individual Borders • Same Format as Margin

  27. Border Properties • border-style: keyword • Keywords • none • dotted • dashed • solid • double • groove • ridge • inset • outset

  28. Border Properties • border-width: thin | medium | thick | # • border-color: value

  29. Special Box Properties • width: # | % • Sets Horizontal Width of a Containing Box • height: # | % • Sets Vertical Height of a Containing Box • float: left | right | none • Sets Position of an Element to Left/Right of Parent Element • clear: none | left | right | both • Controls Flow of Text Around Floated Elements

  30. Special Box Properties • float & clear

  31. Background Properties • background-color

  32. Background Properties • background-image

  33. Background Properties • background-repeat

  34. Background Properties • background-position

  35. List Properties • list-style-type: disc | circle | square | decimal | decimal-leading-zero | lower-roman | upper-roman | lower-greek | lower alpha | lower-latin | upper-alpha | upper-latin | hebrew | armenian | georgian | cjk-ideographic | hiragana | katakana | hira-ganairoha | katakana-iroha | none • Default = disc • Allows Customization of the List Marker • Syntax: ul {list-style-type: circle;}

  36. List Properties • list-style-type

  37. List Properties • list-style-image: url(filename.ext) • Allows Use of Image as List Marker • Syntax: ul {list-style-image: url(paw.gif);}

  38. List Properties • list-style-position: inside | outside • Default = inside • Allows Placement of the List Marker • Syntax: ul {list-style-position: outside;}

  39. Positioning Properties • position: type position size • type = static | relative | absolute | fixed • position = top | left | bottom | right • size = height | width

  40. Positioning Properties • div {position:absolute; left:130px; top:100px;}

  41. Positioning Properties • div {position:absolute; left:130px; top:100px;width: 100px;}

More Related