150 likes | 297 Views
Cascading Style Sheets (CSS). Cascading Style Sheets. Another method of separating content from format Allow precise positioning of elements Allow the application of consistent formats Can be overridden at the local level. HTML and Style Sheets. HTML file references the CSS file
E N D
Cascading Style Sheets • Another method of separating content from format • Allow precise positioning of elements • Allow the application of consistent formats • Can be overridden at the local level
HTML and Style Sheets • HTML file references the CSS file • CSS file contains selectors and declarations • Multiple CSS files may be referenced • All CSS files are applied, only the most recent version of conflicts are applied
CSS Selectors and Declarations • Selectors match to an HTML tag • Declaration lists the styles to be applied to the tag • All tags in the HTML document that match a selector will have the same style
CSS Syntax • Tag {style : value; style : value…} H2{ color : #FF00FF; font-style : bold;}
Applying CSS to a HTML Document • Must refer to the file in the <head> • Need to provide URL, type and rel attributes • Type will be text/css • Rel is usually stylesheet
Rel Settings • Stylesheet • Preferred selection • Alternate • Allows multiple style sheets based on user need • Persistent • Applies style sheet regardless of other style settings
Including CSS in HTML <link href=“style.css” rel=“stylesheet” type=“text/css”>
Inline Style References • Applies style sheet declarations in individual elements • Against the spirit of separation of format and content <li style=“font-weight : bold;”>
HTML Style Element • Insert CSS selectors and declarations inside the HTML document • No separation of content and format • Style tag requires the type attribute • Actual CSS text enclosed in a comment
Example Style Element <style type=“text/css”> <!-- H2 {text-align : left} P {color : blue” --> </style>
Using Div and Span Elements • Span element is used to enclose text • Div element is used to enclose text and tags • Applying a style to these elements will apply the style to everything contained in the tag
CSS and Positioning • Screen is a grid of pixels • X dimension is the height • Y dimension is the width • Z dimension is stacking • (0,0) is upper left of screen • Measurements may be given in inches, mm or pixels
Boxes • Each item is inside of a ‘box’ • Box is given x, y coordinates • Box is given width and height • Box is given flow property • HTML elements may be placed inside of this box
Example Positioning BODY { height ; 10 in } #head{ position: absolute; Width: 100%; Height: 12%; Top: 0; Right: 0; Bottom: auto;}