1
Cascading Style Sheets: CSS
Jay Urbain, Ph.D.
Credits and references: see last page.
Cascading Style Sheets: CSS Jay Urbain, Ph.D. Credits and - - PowerPoint PPT Presentation
Cascading Style Sheets: CSS Jay Urbain, Ph.D. Credits and references: see last page. 1 HTML 5 is structural markup Describing only the content & structure of a document, not the appearance. How does the browser know how to render any
1
Credits and references: see last page.
2
body { background-color: lightblue; } h1 { color: white; text-align: center; } p { font-family: verdana; font-size: 20px; }
body { background-color: lightblue; } h1 { color: white; text-align: center; } p { font-family: verdana; font-size: 20px; }
The selector points to the HTML element you want to style. The declaration block contains one or more declarations separated by semicolons. Each declaration includes a CSS property name and a value, separated by a colon. A CSS declaration always ends with a semicolon, and declaration blocks are surrounded by curly braces.
5
<!DOCTYPE html> <html> <head> <meta … /> <title>SE2840</title> <style type="text/css"> /* Embedded CSS style rules go here…. */ /* Note: you can’t use HTML comments in this section! */ </style> </head> <body> <!-- HTML structural content goes here --> </body> </html>
6
<!doctype html> <html> <head> <meta … /> <title>SE2840</title> <!-- Import the CSS rules from an external .css file: --> <link rel=“stylesheet” href=“stylesheet.css” type=“text/css”/> </head> <body> <!-- HTML structural content goes here --> </body> </html>
link – element to “link” external information. rel=”stylesheet” – relationship between the HTML file and what we are linking to href – URL specifying the stylesheet location type=”text/css” – the type of this information. As of HTML5, you do not need this anymore.
7
<!doctype html > <html> <head>
<meta … /> <title>SE2840</title> <style> /* Embedded CSS style rules go here…. */ </style> <style> /* More embedded CSS style rules go here…. */ </style> <!-- Import the CSS rules from external .css files: --> <link rel=“stylesheet” href=“stylesheet1.css” /> <link rel=“stylesheet” href=“stylesheet2.css” />
</head> <body> <!-- HTML structural content goes here --> </body> </html>
All styles will be applied, but if any style definitions are repeated, the last one wins.
HTML elements! – Different browsers define different default styles – If you view an “unstyled” HTML document in different browsers, they may look somewhat different.
8
Show different browsers
file:///Users/jayurbain/Dropbox/workspaceRDF/ctakes/ctakes-smoking-status- res/src/main/resources/org/apache/ctakes/smokingstatus/analysis_engine/ArtificialSentenceAnnotator.xml file:///Users/jayurbain/Dropbox/MSOE/www/se2840/SE-2840%20Daily%20Detailed%20Outcomes.html
9
10
body { color: Black; } /* applies to all <body> elements and descendants*/ p { color: Red; } /* applies to all <p> elements and descendants*/ h1 strong { color: Navy; } /* applies to all <strong> elements within <h1> elements (and descendants)*/ p em { color: Teal; } /* applies to all <em> elements within <p> elements (and descendants)*/
html h1 head body strong p title p em p em em strong These are called “descendant selectors”
11
Almost like the old “font” attribute which mixed presentation into structure.
12
13
14
Incidentally, there are 17 predefined colors
15
16
17
.definitions { font-family: Arial; } #gnudef { color: Maroon; }
<p id=“gnudef” class=“definitions”> GNU: GNU’s Not Unix </p>
18
19
<link rel="stylesheet" href=“screenstyle.css” media=“screen"/> <link rel="stylesheet" href=“printstyle.css” media=“print"/>
<style media=“screen” > <style media=“print” >
20
Note: other media types are defined; see W3C specs
21
22
23
24
– Built-in or set via Preferences - browser dependent
– IE: part of Internet Options – Firefox plugin extension: https://addons.mozilla.org/en- US/firefox/addon/2108/
– Linked external style sheet(s) – Inline <style> element <head>
#example p { color: blue !important; } ... #example p { color: red; }
25
– p
– p em
– p.warning – .warning
– p#scarytext
26
A 3-digit specificity number Does the selector include an id? One point for each id. Does the selector include a class
class? One point each Does the selector include any element names? One point each
27
h1=001 h1.bluetext=011 body h1=002 h1#topmost=101 Does the selector include an id? One point for each id. Does the selector include a class
class? One point each Does the selector include any element names? One point each