Handout 03. CSS
Handout 03. CSS
Content
Basic CSS
Advanced CSS
1
2/21/2024
Basic CSS
2
2/21/2024
• HTML style sheets are known as Cascading Style Sheets, since can be defined at three
different levels
1. inline style sheets apply to the content of a single HTML element
2. document style sheets apply to the whole BODY of a document
3. external style sheets can be linked and applied to numerous documents, might also
specify how things should be presented on screen or in print lower-level style sheets
can override higher-level style sheets
• User-defined style sheets can also be used to override the specifications of the
webpage designer. These might be used, say, to make text larger (e.g. for visually-
impaired users).
font-family:Courier,monospace <body>
font-style:italic <p style="font-family:Arial,sans-serif;
font-weight:bold text-align:right">This is a
right-justified paragraph in a sans serif
font-size:12pt font-size:large font-size:larger
font (preferably Arial), with some
<span style="color:green">green text</span>.
color:red color:#000080 </p>
background-color:white
<p>And <a style="color:red;
text-decoration:underline text-decoration:none;
text-decoration:none font-size:larger;"
text-align:left text-align:center href="page01.html">here</a>
is a formatted link.
text-align:right text-align:justify
</p>
vertical-align:top vertical-align:middle </body>
vertical-align:bottom </html>
3
2/21/2024
<head>
margin-left:0.1in margin-right:5% <title>Inline Style Sheets</title>
</head>
margin:3em
padding-top:0.1in padding-bottom:5% <body>
<p>Here is an image
padding:3em <img src="VictoriaBldg.jpeg"
alt="image of Victoria Building"
style="margin-left:0.3in;
border-width:thin border-width:thick
margin-right:0.3in;
border-width:5 vertical-align:middle;
border-color:red border-style:double;
border-color:blue" />
border-style:dashed border-style:dotted embedded in text.
border-style:double border-style:none </p>
<ol style="list-style-type:upper-alpha">
whitespace:pre <li> one thing</li>
<li> or another</li>
<ul style="list-style-type:square;
list-style-type:square whitespace:pre">
<li> with this</li>
list-style-type:decimal <li> or that</li>
list-style-type:lower-alpha </ul>
list-style-type:upper-roman </ol>
</body>
</html>
view page 7
<head>
tables for interesting effects <title> Inline Style Sheets </title>
</head>
<body>
<table style="font-family:Arial,sans-serif">
<caption style="color:red;
font-style:italic;
text-decoration:underline">
Student data. </caption>
<tr style="background-color:red">
<th> name </th> <th> age </th>
</tr>
<tr>
<td> Chris Smith </td> <td> 19 </td>
</tr>
<tr>
<td> Pat Jones </td> <td> 20 </td>
</tr>
<tr>
<td> Doogie Howser </td> <td> 9 </td>
</tr>
</table>
</body>
</html>
view page
8
4
2/21/2024
</body>
</html>
view page
10
10
5
2/21/2024
view page
11
11
Pseudo-Class
<html>
•Pseudo-class is used to define a special <!–- CS443 page23.html 17.10.14 -->
<body>
<p> Welcome to my Web page. I am so
happy you are here.
</p>
<p> Be sure to visit
<a href="http://www.cnn.com">CNN</a>
for late-breaking news.
</p>
</body>
</html>
view page
12
12
6
2/21/2024
Pseudo-Element
<html>
• Pseudo-element is used to style <!–- CS443 page23.html 17.10.14 -->
<head>
specified parts of an element. <title>Title for Page</title>
<style type="text/css">
<body>
<p> Welcome to my Web page. I am so
happy you are here.
</p>
<p> Be sure to visit
<a href="http://www.cnn.com">CNN</a>
for late-breaking news.
</p>
</body>
</html>
view page
13
13
14
14
7
2/21/2024
<body>
• simplifies Web pages since only need to <h1>Centered Title</h1>
<h1>The End</h1>
</body>
</html>
view page 15
15
16
8
2/21/2024
Advaned CSS
17
17
Rounded Corners
• With the CSS border-radius property, you can give any element
“rounded corners”.
➢Rounded corners for an element with a border:
#rcorners2 {
border-radius: 25px;
border: 2px solid #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
18
18
9
2/21/2024
Rounded Corners
• With the CSS border-radius property, you can give any element
“rounded corners”.
➢Rounded corners for an element with a specified background color:
#rcorners1 {
border-radius: 25px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
19
19
Rounded Corners
• With the CSS border-radius property, you can give any element
“rounded corners”.
➢If you only specify one keyword, the other value will be “center”
#rcorners3 {
border-radius: 25px;
background: url(paper.gif);
background-position: left top;
background-repeat: repeat;
padding: 20px;
width: 200px;
height: 150px;
}
20
20
10
2/21/2024
Rounded Corners
• With the CSS border-radius property, you can give any element
“rounded corners”.
➢Rounded corners for an element with a background image:
#rcorners3 {
border-radius: 25px;
background: url(paper.gif);
background-position: left top;
background-repeat: repeat;
padding: 20px;
width: 200px;
height: 150px;
}
21
21
Shadows
• With CSS you can add shadow to text and to elements.
• Box Shadows: applies shadow to elements.
box-shadow: 50px 10px 10px 1px lightblue;
• The first value is the horizontal offset — how far the shadow is nudged to the right (or left if it’s
negative)
• The second value is the vertical offset — how far the shadow is nudged downwards (or upwards if
it’s negative)
• The third value is the blur radius — the higher the value the less sharp the shadow. (“0” being
absolutely sharp). This is optional — omitting it is equivalent of setting “0”.
• The fourth value is the spread distance — the higher the value, the larger the shadow (“0” being
the inherited size of the box). This is also optional — omitting it is equivalent of setting “0”.
• The fifth value is a color. That’s optional, too.
22
22
11
2/21/2024
Shadows
• Box Shadows: applies shadow to elements.
box-shadow: 50px 20px 10px 1px lightblue inset;
inset
23
23
Shadows
• Text Shadows: applies shadow to text.
24
24
12
2/21/2024
* {
margin: 0;
padding: 0;
} Example: set the margin and padding on everything
#contact * { in a page to zero and everything within an element
display: block; with the ID “contact” to be displayed as a block
}
25
25
Example: set the border for all <li> child of element has id=“genus_examples”
26
26
13
2/21/2024
<h1>Clouded leopards</h1>
<p>Clouded leopards are cats that belong
to the genus Neofelis.</p>
<p>There are two extant species: Neofelis
nebulosa and Neofelis diardi.</p>
h1 + p { font-weight: bold }
Only the first paragraph, that following the heading, will be made bold.
27
27
Advanced Colors
• We already know that colors can be defined by name, RGB, or hex values
• CSS 3 also allows you to paint away with HSL — hue, saturation, and
lightness
• An HSL color value is specified with: hsl(hue, saturation, lightness).
• Hue is a degree on the color wheel (from 0 to 360):
• 0 (or 360) is red
• 120 is green
• 240 is blue
• Saturation is a percentage value: 100% is the full color.
• Lightness is also a percentage; 0% is dark (black) and 100% is white.
28
28
14
2/21/2024
CSS Transitions
• Transitions allow you to easily animate parts of your design without the
need for the likes of JavaScript
• transition-property: which property (or properties) will transition.
• transition-duration: how long the transition takes.
• transition-timing-function: if the transition takes place at a constant speed or if it
accelerates and decelerates.
• transition-delay: how long to wait until the transition takes place.
29
29
30
30
15
2/21/2024
Transformations
• CSS transforms allow you to move,
rotate, scale, and skew elements.
• The translate() method moves an element
from its current position (according to the
parameters given for the X-axis and the Y-
axis).
• The rotate() method rotates an element
clockwise or counter-clockwise according to
a given degree.
• The scale() method increases or decreases
the size of an element (according to the
parameters given for the width and height).
• The skew() method skews an element along
the X and Y-axis by the given angles.
• The matrix() method combines all the 2D
transform methods into one.
31
31
Position
• specifies the type of positioning
method used for an element
• static: is not affected by the top, bottom,
left, and right properties.
• relative: is positioned relative to its
normal position.
• fixed: always stays in the same place even
if the page is scrolled
• absolute: is positioned relative to the
nearest positioned ancestor (or
document body if no ancestor exists)
• sticky: is positioned based on the user's
scroll position.
32
32
16
2/21/2024
33
33
17