Lec 3-CSS
Lec 3-CSS
Content
Basic CSS
Advanced CSS
2
Basic CSS
3
Motivation
https://www.w3schools.com/css/demo_default.htm
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
4
Content vs. Presentation
5
Content vs. Presentation (cont.)
6
Selectors
7
Example
<!DOCTYPE html>
<html>
<head>
<style>
* {
text-align: center;
color: red;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
<p>Me too!</p>
<p>And me!</p>
</body>
</html>
8
Inline Style Sheets
• Using the style attribute, we can specify presentation style for a single
HTML element
• within tag, list sequence of property:value pairs separated by semi-colons
<body>
<p style="font-family:Arial; text-align:right">
This is a right-justified paragraph in Arial, with some
<span style="color:red">red text</span>.
</p>
<p>And
<a style="color:red; text-decoration:none; font-
size:larger;” href="page01.html">LINK</a>
is a formatted link.
</p>
</body>
9
Inline Style Sheets (cont.)
<!DOCTYPE html>
<html>
<head>
<title>Inline Style Sheets</title>
</head>
<body>
<p style="margin-left:50px; margin-
top:30px"> Text
</p>
<ol style="list-style-type:upper-
alpha">
<li> one thing</li>
<li> or another</li>
<ul style="list-style-type:square">
<li> with this</li>
<li> or that</li>
</ul>
</ol>
</body>
</html>
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
10
Document Style Sheets
11
Document Style Sheets
<!DOCTYPE html>
<html>
<head>
<title>Document Style Sheets</title>
<style type="text/css">
h1 {color:blue;
text-align:center}
p.indented {text-indent:0.2in}
</style>
</head>
<body>
<h1> Centered Title </h1>
<p class="indented">This paragraph
will have the first line indented, but
subsequent lines will be flush. </p>
12
Document Style Sheets (cont.)
<!DOCTYPE html>
<html>
<head>
<title> Inline Style Sheets </title>
<style type="text/css">
table {font-family:Arial,sans-serif}
caption {color:red;
font-style:italic;
text-decoration:underline}
th {background-color:green}
</style>
</head>
<body>
<table>
<caption> Danh sách SV </caption>
<tr><th> Tên </th> <th> MSSV</th></tr>
<tr><td> Minh </td> <td> 20202020 </td></tr>
<tr><td> Mạnh </td> <td> 20212021 </td></tr>
</table>
</body>
</html>
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
13
External Style Sheets
14
Modularity & Style Sheets
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet”
href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
15
Advaned CSS
16
Universal, Child, and Adjacent Selectors
* {
margin: 0; Example: set the margin and padding
padding: 0; on everything in a page to zero and
}
everything within an element with the
#contact * {
display: block; ID “contact” to be displayed as a block
}
17
Universal, Child, and Adjacent Selectors
Example: set the border for all <li> child of element has
id=“genus_examples”
18
Universal, Child, and Adjacent Selectors
<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.
19
Position
20
Position
21
Overlap
22
Rounded Corners
#rcorners2 {
border-radius: 25px;
border: 2px solid #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
23
Rounded Corners
#rcorners1 {
border-radius: 25px;
background: #73AD21;
padding: 20px;
width: 200px;
height: 150px;
}
24
Responsive Web Design
• Example
• https://www.w3schools.com/css/example_withoutviewport.htm
• https://www.w3schools.com/css/example_withviewport.htm
25
Exercises
1. https://www.w3schools.com/css/default.asp
2. https://www.w3schools.com/css/css_exercis
es.asp
3. https://www.freecodecamp.org/learn/2022/r
esponsive-web-design/
4. Build your personal page:
https://ctsv.hust.edu.vn/#/ho-so
26
TRƯỜNG CÔNG NGHỆ THÔNG TIN VÀ TRUYỀN THÔNG
School of Information and Communication Technology
27