CSS Short Notes
CSS Short Notes
Answer: Some default from the browser (HTML tells what browser how)
Formatting information (how to display it) is in separate style sheets (.css files).
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
CSS
CSS HTML
Selector
h1 {
<h1>Today’s Specials</h1>
Tag name color: red;
}
.large {
<p class="large">...
Class attribute font-size: 16pt;
}
#p20 {
<p id="p20">...
Element id font-weight: bold;
}
CSS Pseudo Selectors
hover - Apply rule when mouse is over element (e.g. tooltip)
p:hover, a:hover {
background-color: yellow;
}
a:link, a:visited - Apply rule when link has been visited or not visited (link)
a:visited { a:link {
color: green; color: blue;
} }
CSS Properties
Control many style properties of an element:
● 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; }
CSS Box Model
Margin Total element width =
Border width +
Padding left padding +
right padding +
width left border +
right border +
Element
height
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
body { <body>
font-family: Tahoma, Arial, sans-serif; <h1>First Section Heading</h1>
font-size: 13px; <p>
color: black; Here is the first paragraph, containing
text that really doesn't have any use
background: white;
or meaning; it just prattles on and on,
margin: 8px;
with no end whatsoever, no point to
}
make, really no purpose for existence
h1 { at all.
font-size: 19px; </p>
margin-top: 0px; <div class="shaded">
margin-bottom: 5px; <h1>Another Section Heading</h1>
border-bottom: 1px solid black <p>
} Another paragraph.
.shaded { </p>
background: #d0d0ff; </div>
} </body>
CSS: HTML:
Example Output
CSS in the real world
● CSS preprocessors (e.g. less) are commonly used
○ Add variable and functions to help in maintaining large collections of style sheets
○ Apply scoping using the naming conventions
● Composition is a problem
○ It can be really hard to figure out what rule from which stylesheet is messing things up