Chapter 2 CSS
Chapter 2 CSS
SAMPLE OUTPUT
Styles declared in the internal style sheet affect all matching elements on the
page. In this example, all <h2> page elements are displayed in the color red.
Univeristy of Technology & Applied Sciences 17
Example: Internal/Embedded CSS
Code: Output:
The <link> element instructs the browser to load the external file
specified by the href attribute and to apply the CSS style declarations
contained there.
Univeristy of Technology & Applied Sciences 19
Example: External CSS (mySample.css)
Code Output
Syntax:
OUTPUT
Syntax:
OUTPUT:
Syntax:
Example:
Property Values
text-align : center, left, right, justify
text-decoration : underline, line-through, blink, overline,
underline
color : blue, rgb(255,0,0), #ff0000
text-shadow : H-shadow, V-shadow, blur radius and
color
text-transform : Lowercase, Uppercase and Capitalize
text-indent : Length (in px,pt and %)
letter-spacing : Length (negative and positive values)
Note: The properties and values
word-spacing : listed above
Lengthare
(in the mostpt)
px and common for formatting text via
CSS.
Univeristy of Technology & Applied Sciences 30
CSS Font Properties
The following properties can be specified for any element that contains
text, such as <h1> through <h6>, <p>, <ol>, <ul>, and <a>:
Property Values
font-family : Arial, Verdana, Times New Roman
font-size : large, small, medium,120%, 20px
(pixels)
font-weight : bold, bolder, lighter, normal
font-style : italic, oblique, normal
font-variant : small-caps
Note: The properties and values listed above are the most common for formatting text via
CSS.
Univeristy of Technology & Applied Sciences 31
CSS Color Properties
The following properties can be specified for any element that contains
text, such as <h1> through <h6>, <p>, <ol>, <ul>, and <a>:
Property Values
background-color : SlateBlue, #F08080, RGB(128, 0, 0)
color : SlateBlue, #F08080,
RGB(128, 0, 0)
Note: The properties and values listed above are the most common for formatting text via
CSS.
Univeristy of Technology & Applied Sciences 32
Example: CSS properties for colors
CSS code
p {
color: red;
background-color: yellow;
}
OUTPUT
This paragraph uses the style above
Property Values
background-color : Color name, Hexadecimal
and RGB
background-image : URL(“filename”)
background-repeat : Repeat, No-Repeat, Repeat-x,
Repeat-y
background-attachment : fixed, scroll
background-position : Left Top, Left Center, Left
Bottom, Right Top,
Right Center, Right, Bottom, Center Top,
Center Center, Center Bottom
OUTPUT
Property Values
border : Style, Width, and
Color
border-color : Color name /
Hexadecimal / RGB
border-style : Solid, double, dotted,
dashed, grooved,
Inset, outset
and ridge
border-Width : Medium, thick, thin or length (in
px)
border-radius : Rounded Corners
Four
Univeristy of Technology & Applied Sciences 36
Values, Three values, two values
and one value.(in px or %)
Sample Border Style
Content - The content of the box, where text and images appear
Padding - Clears an area around the content. The padding is transparent
Border - A border that goes around the padding and content
Margin - Clears an area outside the border. The margin is transparent
Property Values
margin : auto, px or %
margin-left : Length in px or %
margin-right : Length in px or %
margin-top : Length in px or %
margin-bottom : Length in px or %
Property
Values
padding : auto, px or
%
padding-left : Length in px
or %
padding-right : Length in px or %
padding-top : Length in px
or %
padding-bottom : Length in px or %
padding:10px 5px;
margin:10px 5px; top and bottom padding are 10px
top and bottom margins are 10px right and left padding are 5px
right and left margins are 5px
padding:10px;
margin:10px; all four paddings are 10px
Univeristy of all four margins are 10px
Technology & Applied Sciences 41
The End
Resources:
www.w3schools.com
https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors
https://msu.edu/course/lbs/126/.../HTML%20Basics%20and%20CSS%20style.ppt
https://web.stanford.edu/group/csp/cs22/css.ppt