CSSPPT
CSSPPT
What is CSS?
Cascading Style Sheet
Stylesheet Language
Standards-based set of properties and attributes to define
styles
To describe the presentation a document
written in a
‘markup language’ like HTML or XML
Markup encoding: <p>My paragraph here.</p>
Defines the style of how things in <p> tags appear.
Font, color, size, margins, etc.
Cascading
Rules to determine how to
apply markup that contains
other markup
Why CSS?
Separate Content from Form
Content is the text and images, marked up to define regions of
specific types
Form defines the “style” for the content
The old way:
<font size=“14px”>
My First Header
</font>
<font size=“12px” color=“red” face=“Verdana”>
My information 1 goes here.
</font>
<font size=“14px”>
My Second Header
</font>
<font size=“12px” color=“red” face=“Verdana”>
Different information goes here.
</font>
CSS Syntax
3 Elements to a CSS Statement
Selector
What HTML sections does it affect?
Property
What attribute of that HTML section will be affected?
Value
What change will be made to that attribute?
Types of css
Inline: the “style” attribute
<p style=“font-color:red;font-size:10px;”>Content</p>
Note, the selector for inline CSS is the tag which contains the style
attribute.
Internal: the <style> markup tag
<html>
<head><style>
p{ background-color: Red;
font-family: serif;
font-color: White; }
</style></head>
<body>
<p>Content</p>
</body>
</html>
External: the .css stylesheet file
Styles declared in an external style sheet will affect all matching elements on
all web pages that link to the style sheet. By editing the external style sheet,
we can make site-wide changes (even to hundreds of pages) instantly.
CSS Syntax: Selectors
There are many kinds of selectors and many ways to reference them:
Type, Class, ID, Pseudo, etc.
p{ font-size: 10px;
font-color: White; }
<p>Content</p>
The Class Attribute – precede the class with a period
<p class=“myinfo”>Content</p>
<div class=“myinfo”>Other content</div>
CSS Syntax: Selectors(contd..)
Id Attribute – selected with the id attribute(#)
<p id=“myinfo”>Content</p>
<div id=“myinfo”>Other content</div>
The group selector– separated with (,)
<p id=“myinfo”>Content</p>
<div >Other content</div>
<h1> Heading </h1>
CSS Syntax: Selectors(contd..)
Universal selector – selected with the * it selects the total content on
webpage
*{ font-size: 10px;
font-color: White; }
<body>
<p> content </p>
<h1> heading </h1>
</body>
CSS properties for colors
p {
color: red;
background-color: yellow;
}
CSS
CS380 11
Specifying colors
p { color: red; }
h2 { color: rgb(128, 0, 196); }
h4 { color: #FF8800; }
CSS
CS380 13
CSS properties for fonts
CS380 14
font-family
p {
font-family: Georgia;
}
h2 {
font-family: "Courier New";
} CSS
CS380 15
More about font-family
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 16
font-size
p {
font-size: 24pt;
} CSS
CS380 17
font-size
p {
font-size: 24pt;
} CSS
CS380 18
font-weight, font-style
p {
font-weight: bold;
font-style: italic;
} CSS
CS380 19
CSS properties for text
CS380 20
background-image
body {
background-image: url("images/draft.jpg");
}
CSS
CS380 31
background-repeat
body {
background-image: url("images/draft.jpg");
background-repeat: repeat-x;
}
CSS
CS380 32
background-position
body {
background-image: url("images/draft.jpg");
background-repeat: no-repeat;
background-position: 370px 20px;
} CSS
But, if you add the style a {display: block;}, they will display as a
vertical navigation menu:
DISPLAY PROPERTIES(contd..)
PROPERTY DESCRIPTION
display:inline-block An element you assign a display of
inline-block is inline by
presentation. But it has the added
advantage of you being able to
apply width and height to it,
which you can't do when the
element is assigned a display of
inline.
When you set the
display:none display property of an
element to none, the
element is completely
taken off the page and
it doesn’t have an effect
on the layout.
DISPLAY PROPERTIES(contd..)
PROPERTY DESCRIPTION
display:flex A display of flex gives you access
to the Flex layout system, which
simplifies how we design and
layout our web pages.
By default, unordered lists (<ul>) appear as bullets and ordered lists
(<ol>) appear as numbers in HTML.
Using CSS, you can modify how list items will appear:
Properties:
list-style, list-style-type, list-style-image, list-
style-position
Values:
disc, circle, square, decimal, decimal-leading-zero,
lower-roman, upper-roman, lower-alpha, upper-alpha,
lower-greek, lower-latin, upper-latin, hebrew,
armenian, georgian, cjk-ideographic, hiragana,
katakana, hiragana-iroha, katakana-iroha, none,
url("graphic.gif")
Examples:
ul { list-style: disc; }
ol { list-style: upper-roman;}
li { list-style: url("blackball.gif");}
ul li { list-style-position: inside;}
Cascading Inheritance