Documente Academic
Documente Profesional
Documente Cultură
L5. Javascript p
L8. XML
Introducing CSS
Cascading Style Sheet (CSS) separates presentation and content Styles allow several attributes to be assigned at once to all elements on a page that are marked with a particular tag Styles
Save time by reducing the amount of HTML required Allow global changes over entire pages or sites R d Reduce f formatting errors tti Allow more variety in formatting beyond that of standard HTML Allow a common format to be defined in one place for an entire site
Introducing CSS
The CSS1 specification was developed in 1996 p p CSS2 was released in 1998 CSS3 is on its way CSSs provide the means to control and change presentation of HTML documents CSS is not technically HTML but can be embedded i i t t h i ll HTML, b t b b dd d in HTML documents Style sheets allow you to impose a standard style on a whole document, or even a whole collection of documents Style is specified for a tag by the values of its properties
CSS 2.1 did not add any new features to the language g g
7
2. Document-level style sheets - apply to the whole document in which they appear 3. External style sheets - can be applied to any number of documents
When more than one style sheet applies to a specific tag in a document, the lowest level style sheet has precedence In a sense, the browser searches for a style property spec, starting with inline, until it finds one (or there isnt one)
Inline styles
Inline styles are applied to individual sections of text Inline style sheets appear in the tag itself <element style=style1:value1; style2:value2; style3:value3;>
10
Embedded styles
You can embed style definitions in a document head using the following form: <style type=text/css> style declarations </style> Where style declarations are the declarations of the different styles to be applied to the document
11
12
<link rel = "stylesheet" type = "text/css" href = "http://www.wherever.org/termpaper.css"> </link> An alternative way to reference an external style sheet: @ p @import url(filename); ( )
Appears at the beginning of the content of a style element (later)
13
14
15
Style inheritance
If a style is not specified for an element it element, inherits the style of its parent element. This is called style inheritance body {color: blue} p {color: red} In the above example, the body element is p y the parent element
16
style = "property_1: value_1; property_2: value_2; property_n: value_n" Document level: Document-level:
Style sheet appears as a list of rules that are the content of a <style> tag The <style> tag must include the type attribute, set to "text/css" The list of rules must be placed in an HTML comment, because it is not HTML Comments in the rule list must have a different form - use C comments (/**/) General form:
<style type = "text/css"> <!-rule list
--></style> Form of the rules: selector {li of property/values} l {list f / l } each property/value pair has the form: property: value Pairs are separated by semicolons, just as in the value of a <style> tag
17
18
Selector forms
Simple Selector Forms
The selector is a tag name or a list of tag names separated by commas names, Examples: h1, h3 p Used to allow different occurrences of the same tag to use different style specifications A style class has a name, which is attached to a tag name For example, p.narrow {property/value list} p.wide {property/value list} The class you want on a particular occurrence of a tag is specified with the class attribute of the tag For example, <p class = "narrow"> ... </p> <p class = "wide"> ... </p>
Class Selectors
19
Selector forms
Generic Selectors
A generic class can be defined if you want a style to apply to more than one kind of tag A generic class must be named, and the name must begin with a period Example, .sale { } Use it as if it were a normal style class <h1 class = "sale"> Weekend Sale </h1> ... <p class = "sale"> </p>
20
Selector forms
id Selectors
An id selector allow the application of a style to one specific element General form: #specific-id {property-value list} p {p p y } Example: #section14 {font-size: 20}
Universal Selectors
* {color: red;} Applies to all elements in the document
21
22
You can apply text and background colors to any page element l t
23
24
25
Absolute units define a font size using one of five t d d it f fi standard units of measurement: t
Millimeters (mm) Centimeters (cm) Inches (in) Points (pt) Picas (pc)
26
27
28
T control f To l font weight f any page element, i h for l use the following style:
font-weight: weight
29
Capitalize:
text-transform: capitalize
30
31 31
You can combine most of them into a single declaration, using the style
font: font-style font-variant font-weight fontsize/lineheight font-family
32 32
List properties
On <li>, list-style-type applies to just that item
<h3> S Some C Common Si l E i Aircraft </h3> Single-Engine Ai ft
<ul> <li style = "list-style-type: disc"> Cessna Skyhawk </li> <li style = "list-style-type: square"> Beechcraft Bonanza </li> <li style = "list-style-type: circle"> Piper Cherokee </li> </ul>
33
List properties
Could use an image for the bullets in an unordered list Example: <li style = "list-style-image: url(bird.jpg)">
34
Formatting Backgrounds
The syntax for inserting a background image is: background-image: url(url)
URL i th l is the location and fil ti d filename of th graphic fil f the hi file you want to use for the background of the Web page
35
36
37
38
Floating an element
The syntax for the float style is: float: position
39
Floating an element
To float an element use the style element, float: position where position is none (to turn off floating), floating) left or right To display an element clear of a floating element, use th style l t the t l clear: position p where position is none, left, right, or both
40
Alignment of text
The text-indent property allows indentation p p y
Takes either a length or a % value
The text align property has the possible text-align values, left (the default), center, right, or justify Sometimes we want text to flow around another element - the float property
The float property has the possible values, left, right, and none (th d f lt) i ht d (the default) If we have an element we want on the right, with text flowing on its left we use the default text align left, text-align value (left) for the text and the right value for float on the element we want on the right
41
Alignment of text
<img src = "c210.jpg" style = "float: right" /> g jpg y g -- Some text with the default alignment - left
42
44
Margin styles
Control you margins with t e following four sty es Co t o your a g s t the o o g ou styles:
margin-top: length margin-right: length margin right: margin-bottom: length margin left: length margin-left:
Margin values can also be negative. This creates an overlay effect by forcing the browser to render one element on top of another You can also combine the four margin styles into a single style:
margin: top right bottom left g p g
45
Padding styles
Styles to set padding are similar to styles to set margins:
padding-top: value padding right: value padding-right: padding-bottom: value padding-left: value
46
Border styles
bo de top dt e gt border-top-width: length border-right-width: length border bottom width: border-bottom-width: length border-left-width: length border width: border-width: top right bottom left border-top-color: color border right color: border-right-color: color border-bottom-color: color border-left-color: color border-color: top right bottom left
47
Border styles
border-top-style: type border-right-style: type border-bottom-style: type border left style: border-left-style: type border-style: top right bottom left
48
Border styles
49
Example
<img src = "c210 jpg " style = "float: right; c210.jpg float: margin-left: 0.35in; margin-bottom: 0.35in" / i b tt 0 35i " />
50
51
52
Pseudo classes
CSS pseudo-classes are used to add special effects to some selectors. selectors
selector:pseudo-class {property:value;} selector.class:pseudo-class {property:value;} p {p p y ;} :active Adds a style to an element that is activated :first-child Adds a style to an element that is the first child of another element :focus Adds a style to an element that has keyboard input focus :hover Adds a style to an element when you mouse over it :lang Adds a style to an element with a specific lang attribute :link Adds a style to an unvisited link :visited Add a style t a visited li k i it d Adds t l to i it d link
53
One problem with the font properties is that they apply to whole elements, which are often t large hi h ft too l Solution: a new tag to define an g element in the content of a larger element - <span> The default meaning of <span> is to leave th content as it is l the t t i
54
- Use <span> to apply a document style sheet to its content <style type = "text/css"> .bigred {font-size: 24pt; font-family: Ariel; color: red} </style> ... <p> p Now is the <span class = "bigred"> best time </span> ever! </p>
55
The <span> tag is similar to other HTML tags, they can be nested and they have id and class attributes Another tag that is useful for style specifications: <div>
Used to create document sections (or ( divisions) for which style can be specified e g A section of five paragraphs for which e.g., you want some particular style
56
Conflict resolution
conflict occurs when there are two or more values for the same property propert on the same element
Sources of conflict:
Conflicting values between levels of style sheets g y Within one style sheet Inheritance can cause conflicts Property values can come from style sheets written by the document author, the browser user, and the browser defaults
Resolution mechanisms:
Precedence rules for the different levels of style sheets Source of the property value The specificity of the selector used to set the property value Property value specifications can be marked to indicate their weight (importance)
57
Conflict resolution
Weight is assigned to a property value by attaching !important to the value Conflict resolution is a multistage process called the cascade: process,
Gather all of the style specs from the different levels of style sheets All available specs, from all sources, are sorted by origin and weight, using the following rules, which are g g given in p precedence order:
Important declarations with user origin Important declarations with author origin Normal declarations with author origin Normal declarations with user origin Any declarations with browser (or other user agent) origin id selectors Class and pseudo-class selectors Contextual selectors Universal selectors
If there are still conflicts resol e them b precedence to the most recently seen conflicts, resolve by recentl specification
58