Beruflich Dokumente
Kultur Dokumente
Style
Style Sheet
Inline
Add a style to an individual element such as a heading or paragraph Utilize the style attribute of the element
Add a style sheet within the <head> </head> element to define styles for a single page Utilize the <style> </style> element. Stylesheet in an external text file with .css extension Utilize the <link /> element within the <head> element
Embedded
External
Which is best?
Can be reused across an entire web site to maintain common look and feel Isolates changes to appearance to a single, separate file Keeps web pages specific to functionality and css files specific to style (modularity is good!)
Cascade to all elements in all pages that <link /> to them Override external style sheets Cascade to a single pages elements Override external & embedded style sheets
Style Syntax
font-family: Garamond; font-color: Red; [selector]: [declaration]; Separate the selector from the declaration with a colon Separate each style with a semicolon Do NOT leave spaces between the property value and the units! If you use "margin-left: 20 px" instead of "margin-left: 20px" it will only work properly in IE6 but it will not work in Mozilla or Netscape.
Inline Styles
Embedded Styles
Utilize the <style> element within the <head> <style type=text/css> <!---p {text-indent: 8pt} a { text-decoration: none; font-family: Verdana; font-size: 14pt} a:hover {background: navy; color: white} ---> </style>
External Styles
Instead of <style> in the <head>, utilize <link /> in the head and write the CSS code in an external file.
Grouping
You can group selectors. Separate each selector with a comma. In the example below we have grouped all the header elements. All header elements will be green:
Classes
You can define custom styles and give them class names, which can then be utilized with the class attribute in your html
<table class=specialtable> <p class=errorRed> ---.specialtable {background-color:red} .specialtable th {font-weight:bold} .specialtable td {font-style:italic} p.errorRed {font-color:red} Class styles begin with a period. You can use or omit the element name to the left of the period
The <span> element allows you to apply styles or classes to anything within them. It will override external and embedded styles, but be overridden if any elements within the <span> specify their own styles. The <div> element does the same, but also includes an id attribute that is referenced by DHTML to show, hide, and position the div on the page. Note: <div> acts like <p> in that it puts whitespace around the item, whereas <span> does not.