lis650 lecture 4 thomas krichel 2004-10-24. today advice css properties –box properties –list...

46
LIS650 lecture 4 Thomas Krichel 2004-10-24

Upload: savannah-mason

Post on 27-Mar-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

LIS650 lecture 4

Thomas Krichel

2004-10-24

Page 2: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

today

• Advice• CSS Properties

– Box properties– List properties– Classification properties

• Fun with selectors• More CSS properties

– Generated content properties– User interface properties– Page properties

Page 3: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

advice for cheaters

• Within a style sheet, for example the contents of a <style> element, you can import another file using the @import command

@import url(http://www.art.org/kitsch.css);• or

@import "http://www.art.org/kitsch.css";• these two ways appear to be equivalent

Page 4: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

media dependent styles• Remember the media CSS knows about ?• Using @import, you can import different types

for different media

@import "URI" medialist

where medialist is a list of one or more media, separated by comma

• Example

@import “challenged.css" braille, handheld

Page 5: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

advice about spacing

• Traditionally only use horizontally, the em nowadays is the height of the font, and should be used vertically as well, as in div.menu {padding: 1.5em; margin: 1.5em}

• For body, use %ages, as in body {margin-left: 15%; margin-right: 0%}

• To create a menu, do something like div.menu {float: left; width: 15em}

Page 6: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

the 'inherit' value

• Each property can have the 'inherit' value. In this case, the value of the property for the element is determined by the containing element.

• Sometimes, 'inherit' is the default value.

Page 7: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

validating CSS

• It is at http://jigsaw.w3.org/css-validator/• Check your style sheet there when you wonder

why the damn thing does not work.• Note that checking the style sheet will not be

part of the assessment of the web site.

Page 8: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

box properties V

• {z-index: } let you set an integer value for a layer on the canvas where the element will appear.

• If element 1 has z-index value 1 and element 2 has z-index value number 2, element 2 lies on top of element 1.

• A negative value means that the element contents is behind its containing block.

• the initial value is 'auto'.• browser support for this property is limited.

Page 9: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

general background to foreground order

• For an element, the order is approximately– background and borders of element– children of the element with negative z-index– non-inline in-flow children – children that are floats– children that are in-line in-flow– children with z-index 0 or better

• not worth remembering for quiz

Page 10: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

box properties VI

• The {visibility: } property sets the visibility of a tag. It takes values– 'visible' The generated box is visible. – 'hidden' The generated box is invisible (fully

transparent), but still affects layout. – 'collapse' The element collapses in the table. Only

useful if applied to table elements. Otherwise, 'collapse' has the same meaning as 'hidden'.

• With this you can do sophisticated alignments

Page 11: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

box properties VII

• We now look at overflow and clipping. When a box contents is larger than the containing box, it overflows.

• {overflow:} can take the values– visible contents is allowed to overflow– hidden contents is hidden– scroll UA displays a scroll device at the edge of the box– auto leave to the user agent to decide what to do

Page 12: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

box properties VIII• The {clip:} properties sets which area of a box is

visible.• When the {overflow: } property is not set to

'hidden' it will take no effect.• It only applies to absolutely positioned elements.

p {overflow: hidden; clip: rect(15px, -10px, 5px, 10px)}

• IE v6 does not support it. • Example at clip_test.html in the examples

section of the class web site.

Page 13: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

box properties IX

• {min-height:} sets the minimum height of a box• {max-height:} sets the maximum height of a box• They can take length values or they can use a

percentage of the containing block.• The containing block is usually the parent

element.

Page 14: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

list properties• {list-style-position: } can take the value ‘inside’ or

‘outside’. The latter is the default, the property refers to the position of the list item start marker

• {list-style-property: }– takes the values ‘disc’, ‘circle’, ‘square’, ‘none’ with an

unordered list– takes the value ‘decimal’, ‘lower-roman’, ‘upper-

roman’, ‘lower-alpha’, ‘upper-alpha’ with ordered list, and some others

• {list-style-image: } define the bullet point of a list as a graphic, use url(URL) to give the location of the graphic.

Page 15: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

classification properties I

• {display: } sets the display type of an element, it take the following values– 'block' displays the tag contents as a block– 'inline' displays it as inline contents– 'list-item' makes it an item of a list, you can then

attach list properties to it– 'none' does not display it– 'run-in' (see later) – 'compact' (see later)

Page 16: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

classification properties II

• {display: } also takes the following values– table -- table-footer-group– table-row -- table-row-group– table-cell -- table-column– table-caption -- table-column-group– inline-table -- table-header-group

• these means that they behave like the table elements that we already discussed

Page 17: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

run-in box

• If a block box (that does not float and is not absolutely positioned) follows the run-in box, the run-in box becomes the first inline box of the block box.

• Otherwise, the run-in box becomes a block box. • Example on next page

Page 18: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

example for run-in box

<head><title>a run-in box example</title>

<style type="text/css">

h3 { display: run-in }

</style> </head> <body>

<h3>a run-in heading </h3><p>and a paragraph of text that follows it and it continues on the line of the h3</p>

</body>

Page 19: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

compact box

• If a block-level box follows the compact box, the compact box is formatted like a one-line inline box. The resulting box width is compared to one of the side margins of the block box,– left margin if direction is left-to-right– right margin if direction is right-to-left

• If the inline box width is less than or equal to the margin, the inline box is given a position in the margin as described immediately below.

• Otherwise, the compact box becomes a block box.

Page 20: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

compact box example

<div style="dt { display: compact }

dd { margin-left: 4em }>

<dl> <dt>short <dd><p>description goes here.

<dt>too long for the margin <dd><p>description goes here.

</div>

Page 21: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

classification properties III

• The {whitespace:} property controls the display of white space in a block level tag.– 'normal' collapses white space– 'pre' value similar to <pre> tag– 'nowrap' ignores carriage returns only

• It seemed not to work in firefox last time I tried.

• now we turn to cool selectors

Page 22: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

remember the basic selector

• The basic selector is a comma-separated list of elementary selectors.

• Often, the elementary selectors are HTML elments, e.g.

h1, h2 {text-align: center}

will center all <h1> and <h2> element contents• but the selectors can be more precise

Page 23: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

class selectors• This is the standard way to style up a class

.class { property1: value1, property2: value2 …}

will give all the properties and values to any element in the class class.

• Recall HTML, when you have set the you can apply the class

<element class="class">

will apply all the attributes of the class class to the element element. Note that you can place any tag into several classes, use blanks to separate the class names

Page 24: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

fun with selectors

• * selects any element.• E selects any element called E• E F selects any F element that is in the contents

of an E element, as a child, grand-child etc• E > F selects any F tag that is a child of an E

element. This is more restrictive than the previous selector.

• E:first-child selects E when E is the first child of its enclosing element

• E:link selects an E element if it is in the contents of an <a> element

Page 25: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

more selectors

• E:visited selects element E if E if it is in the contents of a link and the link has been visited.

• E:active, E:hover, E:focus selects element E during certain user actions with the mouse.

• E:lang(c) selects element E if it is in the human language c

• E + F selects any F element immediately preceded by an E element start tag.

Page 26: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

more selectors

• E[a] selects any E element with an attribute "a", whatever the value

• E[a="v"] select any E element whose "a" attribute value is exactly equal to "v".

• E[a~="v"] selects any element E whose "a" attribute value is a list of space-separated values, one of which is exactly equal to "v". Useful for classes, because you can put an element into several classes, separated by blanks.

Page 27: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

more selectors

• E[lang|="en"] selects any E element whose "lang" attribute has a hyphen-separated list of values beginning (from the left) with "en". This would select all en languages, be they en-us or en-gb

• E:first-letter selects the first letter in the content of element E

• E:first-word selects the first word in the contents of element E

Page 28: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

convenient shorthand

• We have already seen some.• E.m is a convenient shorthand for E[class~="m"]• E#myid is a convenient shorthand for

E[id="myid"]• .m is a convenient shorthand for *.m

Page 29: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

E:before and E:after

• E:before or E:after can be used to add contents before or after a element E.

• We will deal come to these when we discuss generated contents properties.

• This will be coming up after the examples for selectors that we will discuss now.

Page 30: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

examples

• h1, h2, h3 { font-family: sans-serif } • h1 { color: red }

em { color: red }

h1 em { color: blue } • div * p • div p *[href] • body > p { line-height: 1.3 } • div ol > li p

Page 31: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

more example• h1 + p {text-indent: 0} • h1 + h2 {margin-top: -5mm} • h1.opener + h2 {margin-top: -5mm}• h1[title] {color: blue} • span[class="example"] {color: blue } • span[hello="Cleveland"][goodbye="Columbus"]

{ color: blue} • a[rel~="copyright"] {color: red}• a[href="http://www.w3.org/"] {background-color:

grey}• *[lang=fr] {display: none}

Page 32: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

more examples

• *[lang|="en"] {color : red } • .dialog.romeo {voice-family: "Lawrence Olivier",

charles, male} • a:link {color: red} /* unvisited links */ • a:visited {color: blue} /* visited links */ • a:hover {color: yellow} /* user hovers */• a:active {color: lime} /* active links */ • a.external:visited {color: blue}

Page 33: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

more examples

• html:lang(fr) { quotes: '« ' ' »' } • html:lang(de) { quotes: '„' ‘”'}• *:lang(fr) > q { quotes: '« ' ' »' } • *:lang(de) > q { quotes: '„' ‘”'}

(quotation style depending on the surrounding language, not the language of the quote!)

Page 34: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

more examples

• a[rel~="copyright"] • a[href="http://openlib.org/home/krichel"]• div > p:first-child • a:focus:hover • p > * > p• div[class~="ny"][id="albany"]

Page 35: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

example: drop caps with uppercase

• CSSp { font-size: 12pt; line-height: 12pt }

p:first-letter { font-size: 200%; font-style: italic; font-weight: bold; float: left }

span { text-transform: uppercase }

• HTML<p><span>The first</span> few words of an article in

The Economist.</p>

Page 36: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

generated contents properties• generated contents is, for example, the bullet

appearing in front of a list item.• {content:} can be used with the :before and :after

selectors.The content can be– a text string– a url(URL) where the contents is to be found– a attr(att) where att is the name of the attribute, the

content of which is being inserted

• Example• p.note:before {content: "note"} will insert the

string "note" before any paragraph in the class 'note'.

Page 37: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

generated contents properties II

• Here are some counter properties– {counter-reset: counter} resets a counter counter– {counter-increment: counter} increments a counter– {counter(counter)} uses the counter

• Exampleh1:before {counter-increment: chapter_counter;counter-reset: section_counter;content: "Chapter " counter(chapter_counter) ":"}

and then we can use h2 for the sections, of course!

• browser support uncertain!

Page 38: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

user interface properties I

• There is a {cursor:} property to change the shape of the cursor. It takes the following values– auto -- crosshair -- default– pointer (something suggesting a link)– e-resize –ne-resize –nw-resize –n-resize –se-resize– sw-resize, --s-resize –w-resiz (Indicate that some edge

is to be moved)– text (usually as an I) --wait (watch or hourglass)– help (question mark or balloon)– url (with a uri to svg file, that has the graphic to show)

• use these to totally confuse your users

Page 39: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

user interface properties II

• outlines are like borders, but they don't take up space. they are decorative shades drawn around some

• {outline-width: } sets the width• {outline-style: } takes the same values as {border-

style: }• {outline-color: } has a color value.

Page 40: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

paged media support I

• CSS has the concept of a page box in which paged output should be placed into.

• @page rule can be used to specify the size of the page

• @page {size: 8.5in 11in} • Valid values are one or two lengths and they

words ‘portrait’ and ‘landscape’. The latter will depend on the default print sheet size, country-specific.

Page 41: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

paged media support II

• You can add {margin: }, {margin-top: }, {margin-left: }, and {margin-right: } properties. They will add to the margins that the printer will set by default. The default printer margins are beyond your control.

• You can add a {marks: crop} property to add crop marks

• You can add a {mark: cross} property to create registration marks.

Page 42: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

paged media support III

• You can use three pseudoclasses to specify special cases– :first for the first page– :left for any left page– :right for any right page

• Example– @page :first {margin-top: 3in}

Page 43: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

named pages

• You can give a page rule an optional name. Example

@page rotated { size: landscape}• Then you can use this with the ‘page’ property to

specify specific ways to print things. Example

table {page: rotated}

will print the table on a landscape sheet. This comes in handy for bulky tables.

Page 44: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

actual page breaking

• Pages will break if – the current page box flows over or if– a new page format is being used with a {page: }

property

• You can take some control with the {page-break-before: } and {page-break-after: } properties. They take the values– auto – always – avoid – left – right

The latter two make sure that the element is on a left or right page. Sometimes this will require two page breaks.

Page 45: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

conclusions

• These are not all the properties.• Audio properties are still missing• But I am not sure if I should go into more.

Page 46: LIS650 lecture 4 Thomas Krichel 2004-10-24. today Advice CSS Properties –Box properties –List properties –Classification properties Fun with selectors

http://openlib.org/home/krichel

Thank you for your attention!