Cascading Style Sheets (CSS) : Mendel Rosenblum
Cascading Style Sheets (CSS) : Mendel Rosenblum
(CSS)
Mendel Rosenblum
Answer: Some default from the browser (HTML tells what browser how)
Formatting information (how to display it) is in separate style sheets (.css files). Use
Consider can you make all the text in the app slightly bigger? Or
purple is our new company color.
body {
font-family: Tahoma, Arial, sans-serif;
Declaration color: black;
Block background: white;
margin: 8px;
}
Property Value
CS142 Lecture Notes - CSS 4
CSS
CSS HTML
Selector
h1 {
color: red; <h1>Today’s Specials</h1>
Tag name
}
.large {
font-size: 16pt; <p class="large">...
Class attribute
}
#p20 {
font-weight: bold; <p id="p20">...
Element id
}
● Coloring
● Size
● Position
● Visibility
● Many more: (e.g. p: { text-decoration: line-through; })
● Predefined names: red, blue, green, white, etc. (140 standard names)
● 8-bit hexadecimal numbers for red, green, blue: #ff0000
R G B
● 0-255 decimal intensities: rgb(255,255,0)
R G B
● Percentage intensities: rgb(80%,80%,100%)
R G B
Example: h1: { color: red; }
left margin +
right margin
1mm millimeters
2cm centimeters
0.2in inches
Relative
2em 2 times the element’s current font size
<head>
<link rel="stylesheet" type="text/css" href="myStyles.css" />
<style type="text/css">
body {
font-family:
Tahoma, Arial,
sans-serif;
</style> Page-specific styles
}
</head>
<body>
<div style="padding:2px; ... ">
</body>
Element-specific styles
● Composition is a problem
○ It can be really hard to figure out what rule from which stylesheet is messing things up