Css
Css
Notepad++
Komodo Edit
Froala
Dreamweaver
Vim
Sublime Text 3
Brackets.io
Cascading Style Sheets (CSS)
3
CS380
Basic CSS rule syntax
4
selector {
property: value;
property: value;
...
property: value;
}
CSS
p {
font-family: sans-serif;
color: red;
}
CSS
A CSS file consists of one or more rules
Each rule starts with a selector
A selector specifies an HTML element(s) and then applies style
properties to them
a selector of * selects all elements
Attaching a CSS file <link>
5
<head>
...
<link href="filename" type="text/css" rel="stylesheet" />
...
</head> HTML
HTML
A page can link to multiple style sheet files
In case of a conflict (two sheets define a style for the
CS380
Embedding style sheets: <style>
6
<head>
<style type="text/css">
p { font-family: sans-serif; color: red; }
h2 { background-color: yellow; }
</style>
</head>
HTML
HTML
This is a paragraph
output
CS380
CSS properties for colors
8
p {
color: red;
background-color: yellow;
}
CSS
This paragraph uses the style above
output
property description
color color of the element's text
color that will appear behind
background-color
the element
CS380
Specifying colors
9
p { color: red; }
h2 { color: rgb(128, 0, 196); }
h4 { color: #FF8800; }
CSS
p, h1, h2 {
color: green;
}
h2 {
background-color: yellow;
} CSS
output
A style can select multiple elements separated by
commas
The individual elements can also have their own
stylesCS380
CSS comments /*…*/
11
/* This is a comment.
It can span many lines in the CSS file. */
p {
color: red; background-color: aqua;
} CSS
CS380
CSS properties for fonts
12
property description
font-family which font will be used
how large the letters will be
font-size
drawn
used to enable/disable italic
font-style
style
used to enable/disable bold
font-weight
style
mplete list of font properties (http://www.w3schools.com/css/css_reference.asp#
CS380
font-family
13
p {
font-family: Georgia;
}
h2 {
font-family: "Courier New";
} CSS
CS380
More about font-family
14
p {
font-family: Garamond, "Times New Roman", serif;
} CSS
output
We can specify multiple fonts from highest to lowest priority
Generic font names:
serif, sans-serif, cursive, fantasy, monospace
If the first font is not found on the user's computer, the next is tried
Placing a generic font name at the end of your font-family value, ensures that every
computer will use a valid font
CS380
font-size
15
p {
font-size: 24pt;
} CSS
CS380
font-size
16
p {
font-size: 24pt;
} CSS
CS380
font-weight, font-style
17
p {
font-weight: bold;
font-style: italic;
} CSS
output
Either of the above can be set to normal to turn
them off (e.g. headings)
CS380
CSS properties for text
18
property description
alignment of text within its
text-align
element
decorations such as
text-decoration
underlining
line-height,
gaps between the various
word-spacing,
portions of the text
letter-spacing
indents the first letter of each
text-indent
paragraph
mplete list of text properties (http://www.w3schools.com/css/css_reference.asp#
CS380
text-align
19
We wants it, we needs it. Must have the precious. They stole it from us.
Sneaky little hobbitses. Wicked, tricksy, false!
output
text-align can be left, right, center, or
justify
CS380
text-decoration
20
p {
text-decoration: underline;
}
CSS
This paragraph uses the style above.
output
can also be overline, line-through, blink, or
none
effects can be combined:
text-decoration: overline underline;
CS380
The list-style-type property
21
ol { list-style-type: lower-roman; }
CS380
Body styles
22
body {
font-size: 16px;
}
CSS
CS380
Cascading Style Sheets
23
CS380
Inheriting styles
24
CSS
This is a heading
A styled paragraph. Previous slides are available on the website.
• A bulleted list
output
when multiple styles apply to an element, they are
inherited
a more tightly matching rule can override a more
general inherited rule
CS380
Styles that conflict
25
CSS
This paragraph uses the first style above.
This heading uses both styles above.
output
CS380
W3C CSS Validator
26
<p>
<a
href="http://jigsaw.w3.org/css-validator/check/referer">
<img src="http://jigsaw.w3.org/css-validator/images/vcss"
alt="Valid CSS!" /></a>
</p> CSS
output
jigsaw.w3.org/css-validator/
checks your CSS to make sure it meets the
official CSS specifications
CS380
CSS properties for backgrounds
27
property description
background-color color to fill background
background-image image to place in background
placement of bg image within
background-position
element
whether/how bg image
background-repeat
should be repeated
whether bg image scrolls
background-attachment
with page
shorthand to set all
background
background properties
CS380
background-image
28
body {
background-image: url("images/draft.jpg");
}
CSS
CS380
background-repeat
29
body {
background-image: url("images/draft.jpg");
background-repeat: repeat-x;
}
CSS
CS380
background-position
30
body {
background-image: url("images/draft.jpg");
background-repeat: no-repeat;
background-position: 370px 20px;
} CSS
CS380
<html>
HTML <div> T <head>
ag <style>
.myDiv {
border: 5px outset red;
The <div> tag background-color: lightblue;
defines a text-align: center;
division or a }
section in an </style>
HTML </head>
document. It is <body>
used as a
<div class="myDiv">
container for <h2>This is a heading in a div
HTML element</h2>
elements - <p>Welcome to my first web site.</p>
which is then </div>
styled with
CSS or </body>
manipulated </html>
with
JavaScript.
Create A
Password <form>
Validation <label for="usrname">Username</
Form label>
<input type="text" id="usrname" name
We use the
pattern attribute ="usrname" required>
(with a regular
expression) <label for="psw">Password</label>
inside the
< input
password field to
set a restriction type="password" id="psw" name="psw" p
for submitting attern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).
the form: {8,}" title="Must contain at least one
it must contain 8 number and one uppercase and lowercase
or more letter, and at least 8 or more
characters that characters" required>
are of at least one
number, and one
uppercase and <input type="submit" value="Submit">
lowercase letter. </form>
CSS Selectors
p {
margin-top: 100px;
margin-bottom: 100px;
margin-right: 150px;
margin-left: 80px;
}
CSS Padding
div {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
padding-left: 80px;
}