130 likes | 203 Views
CSS Cavalcading Style Sheets. Hussain Al-Arrayed. Pre-CSS Concepts. Containment: makes it possible for the web browser to know precisely where content contained by an element begins and end. i.e. E ach <P> should have a </P> XHTML.
E N D
CSS Cavalcading Style Sheets Hussain Al-Arrayed
Pre-CSS Concepts • Containment: makes it possible for the web browser to know precisely where content contained by an element begins and end. i.e. Each <P> should have a </P> XHTML. • Block-level (h1..h6, ul, p,..) vs. Inline text elements (b, i, u,…).
Why Need CSS? • HTML made text display and formatting easy. • It works well when you have few pages that are short in length. • Imagine you manage a website with tens of pages, each heading should be in green <font color=“green”><h3>… • Suppose you want to change it to red?
Example of CSS <head> <style type="text/css"> h3 {font-family: Arial, sans-serif;color:green; text-align:center;} p {font-family: "times new roman", serif; color:red; text-align:left;} </style> </head>
CSS – What do they do? Allows you to override the default browser style sheet. • Easy to modify • Save time • Reduce the error
CSS • CSS is basically a set of rules to indicate how to display each HTML element. • Each CSS rule consist of a selector and a declaration. • Ex:
CSS • A selector identifies the tag (element) to be styled, while the declaration identifies the style(s) to be applied. • Each declaration contains pair(s) of properties and values. • Ex:
CSS - Selectors • You can group selectors for a group of declarations: Ex: H1, H2, H3 { font-style: bold } • Multiple Selectors: Ex: H1, H2, H3 { font-style: bold } H1 {color:silver} H2 {color:blue} H3 {font: italic}
Contextual Selector • You can specify an element style which will only be applied within another element. Ex: p b {color : maroon} means that only text within the <b> inside a <p> will be in maroon!
Class Selector • Class selectors will override any style selected initially. • Class selector rule example: Ex: .isgreen {color : green} • If used with any style it, it will override the default color. Ex: <h2 class="isgreen">
Placing Style Sheets • Inline Style Sheets, styles can be defined within tags: Ex: <p style=“color:silver;”> Not recommended – mixing style with structure. • Internal Style Sheets, what we have been discussing so far, i.e. use of <style> tag
Placing Style Sheets • External Style Sheets: Write the style in a separate file (mySS.css) • Refer to the file using a link tag in the head section of the HTML file. • <link rel=“stylesheet” type=“text/css” href=“mySS.css”>