CSS
CSS
CSS stands for Cascading Style Sheets. Used to design, style and define layout of webpage.
CSS Syntax
Inline Style
<tag style = “property: value;”
Embedded Style
<head>
<style type=“text/css”>
selector { property : value; }
</style>
</head>
External Style Sheet
<head>
<link rel=“Style Sheet”
type=“text/css” href=“style.css” />
</head>
Font Properties
Font-Family
P { font-family: "New Century Schoolbook", Times, serif; }
Changes the font family of certain words, sentences,
paragraphs, etc.
Font-Style
H1 { font-style: oblique; }
P { font-style: normal; }
Changes text: normal, oblique, and italics.
Font-Variant
SPAN { font-variant: small-caps; }
Used to display font in normal or small-caps.
Font-Weight
H1 { font-weight: 800; } or P { font-weight: normal; }
Used to specify the weight of the font.
Font-Size
H1 { font-size: large; } or P { font-size: 12pt; }
LI { font-size: 90%; }
STRONG { font-size: larger; }
Used to modify the size of the displayed font.
Font
P { font: italic bold 12pt/14pt Times, serif; }
Used to combine all properties of fonts.
Color & Background Properties
Color
H1 { color: blue; } or H2 { color: #000080; }
Changes the color of text.
Background-Color
BODY { background-color: white; }
H1 { background-color: #000080; }
Sets the background color of an element.
Background-Image
BODY { background-image: url(/images/foo.gif); }
P { background-image: url(http://www.htmlhelp.com/bg.png); }
Sets the background image of an element.
Background-Repeat
BODY { background: white url(candybar.gif);
background-repeat: repeat-x; }
Determines how a specified background image is repeated.
The repeat-x value will repeat the image horizontally while the repeat-y value will repeat the image vertically.
Background-Attachment
BODY { background: white url(candybar.gif);
background-attachment: fixed; }
Determines if a specified background image will scroll with the content or be fixed with regard to the canvas.
Background
BODY { background: white url(http://www.htmlhelp.com/foo.gif); }
BLOCKQUOTE { background: #7fffd4; }
P { background: url(../backgrounds/pawn.png) #f0f8ff fixed; }
TABLE { background: red url(leaves.jpg) no-repeat bottom right; }
Used to combine all properties of background.
Text Properties
Word-Spacing
P EM { word-spacing: 0.4em; }
P.note { word-spacing: -0.2em; }
Defines an additional amount of space between words.
Letter-Spacing
H1 { letter-spacing: 0.1em; }
P.note { letter-spacing: -0.1em; }
Defines an additional amount of space between characters.
Text-Decoration
A:link, A:visited, A:active { text-decoration: none; }
Allows text to be decorated through one of five properties:
underline, overline, line-through, blink, none.
Vertical-Align
IMG.middle { vertical-align: middle; }
IMG { vertical-align: 50%; }
.exponent { vertical-align: super; }
Used to alter the vertical positioning of an inline element,
relative to its parent element or to the element's line.
Text-Transform
H1 { text-transform: uppercase; }
H2 { text-transform: capitalize; }
Allows for capitalizing the first letter of each word (capitalize), capitalizing all letters of a word (uppercase), using all small letters in each word(lowercase), and the initial value(none).
Text-Align
H1 { text-align: center; }
P.newspaper { text-align: justify; }
Used to justify text left, center, right, and justify.
Text-Indent
P { text-indent: 5em; }
Used to specify the amount of indentation prior to the first line of text.
Line-Height
P { line-height: 200%; }
Used to control the spacing between baselines of text.
Classification Properties
List-Style-Type
LI.square { list-style-type: square; }
UL.plain { list-style-type: none; }
OL { list-style-type: upper-alpha; }
OL OL { list-style-type: decimal; }
OL OL OL { list-style-type: lower-roman; }
Specifies the type of list-item marker, and is used if list-style-
image is none or if image loading is turned off.
List-Style-Image
UL.check { list-style-image: url(/LI-markers/checkmark.gif); }
UL LI.x { list-style-image: url(x.png); }
Specifies the image that will be used as list-item marker when image loading is turned on, replacing the marker specified in the list-style-type property.
List-Style-Position
UL { list-style-position: inside; }
Determines where the marker is placed in regard to the list
item. If the value inside is used, the lines will wrap under the marker instead of being indented. outside is default.
Box Properties
Margin-Top
BODY { margin-top: 5pt; }
Sets the top margin of an element by specifying a length or a percentage.
Margin-Right
P.narrow { margin-right: 50%; }
Sets the right margin of an element by specifying a length or a percentage.
Margin-Bottom
DT { margin-bottom: 3em; }
sets the bottom margin of an element by specifying a length or a percentage.
Margin-Left
ADDRESS { margin-left: 50%; }
sets the left margin of an element by specifying a length or a percentage.
Margin
BODY { margin: 5em; }
P { margin: 2em 4em; }
DIV { margin: 1em 2em 3em 4em; }
Sets the margins of an element by specifying top, bottom, left and right margins -- all either specifying length or percentage.
Padding-Top
P { padding-top: 20%; }
Describes the amount of space between the top border and
the content of the selector.
Padding-Right
P { padding-right: 20 px; }
Describes the amount of space between the right border and the content of the selector.
Padding-Bottom
P { padding-bottom: 5 em; }
Describes the amount of space between the bottom border
and the content of the selector.
Padding-Left
P { padding-left: 15 px; }
Describes the amount of space between the left border and
the content of the selector.
Padding
BLOCKQUOTE { padding: 2em 4em 5em 4em; }
Shorthand for the padding-top, padding-right, padding-bottom, and padding-left properties.
Border-Top-Width
P { border-top: 20%; }
Used to specify the width of an element's top border.
Border-Right-Width
P { border-right: 20%; }
Used to specify the width of an element's right border.
Border-Bottom-Width
P { border-bottom: 20%; }
Used to specify the width of an element's bottom border.
Border-Left-Width
P { border-left: 20%; }
Used to specify the width of an element's left border.
Border-Width
P { border-width: 20%; }
P { border-width: 10px 5px 10px 5px; }
Used to set the width of an element's border (either all
borders, or specifying top border, right border, bottom border,
left border).
Border-Color
P { border-color: #00000; }
Used to set the color of an element's border.
Border-Style
P { border-style: dotted; }
Sets style of a border - none, dotted, dashed, solid, double.
Border-Top
P { border-top: 10px, red, double; }
Sets the width, style, and color of an element's top border.
Border-Right
P { border-right: 10px, red, double; }
Sets the width, style, and color of an element's right border.
Border-Bottom
P { border-bottom: 10px, red, double; }
Sets the width, style, and color of an element's bottom border.
Border-Left
P { border-left: 10px, red, double; }
Sets the width, style, and color of an element's left border.
Border
P { border: 10px, red, double; }
Sets the width, style, and color of an element's border.
Width
P { width: 15px; }
H1 { width: 35%; }
.foo { width: auto; }
Each block-level or replaced element can be given a width,
specified as a length, a percentage, or as auto.
Height
P { height: 15px; }
H1 { height: 35%; }
.foo { height: auto; }
Each block-level or replaced element can be given a height,
specified as a length or as auto.
Float
P { float: left; }
H1 { float: right; }
.foo { float: none; }
Allows text to wrap around an element (left, right, none).
Clear
P { clear: left; }
H1 { clear: right; }
.foo { clear: none; }
Specifies whether an element allows floating elements to its
sides (left, right, none).
Defines a sub/super-scripted text