Cascading Style Sheet
Cascading Style Sheet
Cascading Style Sheet
CSS Syntax
CSS contain rules and declarations that instruct a
program, such as a Web browser, how to display
certain elements.
Defining Styles
The href attribute, like that for the <a> (anchor) element,
specifies the location of the style sheet file on the system.
Both relative and absolute URLs can be used as the value for
the href attribute.
-->
</style>
Notice that the section where the global styles are defined is contained within an
HTML5 comment. This is to hide the actual contents of the style definition from older
browsers that dont support CSS. The comment tags are not necessary to make
CSS work, but if they are not provided in an XHTML document, older Web browsers
may actually display the style property definitions on the Web page!
Inline Styles
External styles
Embedded styles
Inline styles
Style Precedence
For example, a developer could use a linked CSS file for the
common formatting properties for all of the documents on a
Web site. If one particular document needed special
formatting properties, the developer could define global
styles within that document without affecting the rest of the
documents. The same is true for individual elements. A
developer who wanted all of the <h1> elements in a
document to be blue would define this in the <style>
Element or in a linked CSS file. If one particular <h1>
element needed red text, the developer could define the red
style on that particular element, which would override the
blue setting of the other <h1> elements.
CSS Properties
1.
Font properties define font styles such as font family or type, size,
weight, and variant.
2.
3.
Color and image properties define the color and background formatting
of text and images. These properties can also define the position of a
background image and whether the image is repeated (tiled).
4.
Border properties define the style of borders for elements like tables and
images, as well as for the entire document. Border properties include
width, height, style, color, margins, and padding.
5.
Display properties define the style for the structure of the document.
These properties can define the placement of elements within the
document, such as block or inline, and how whitespace is formatted
within the document.
Font Properties
Property
font
font-family
font-size
font-style
font-variant
font-weight
Description
Value Example(s)
arial, courier
small, x-small,
medium, large,
x-large
Style of font.
italic, bold
Font rendering.
normal, small-caps
Text Properties
Property
word-spacing
letter-spacing
text-align
vertical-align
text-indent
text-transform
line-height
text-decoration
Description
Value Example(s)
uppercase, lowercase,
capitalize, none
underline, overline,
blink, line-through,
none
Color Properties
Property
color
background
backgroundcolor
Description
Value Example(s)
Text color
backgroundimage
backgroundattachment
backgroundposition
backgroundrepeat
repeat, repeat-x,
repeat-y, no-repeat
Border Properties
Property
border-color
border-width
border-style
margin-top
Description
Value Example(s)
margin-bottom
margin-left
margin-right
padding-top
Description
Value Example(s)
padding-left
padding-right
clear
float
Floating element.
Height of an element.
Width of section
padding-bottom
height
width
Display Properties
Property
display
white-space
visibility
Description
Value Example(s)
block, inline
Whitespace formatting.
inherit, visible,
hidden
CSS Rules
font-size: 12pt;
font-family: arial;
}
h1, h2, p {
color: red;
font-size: 12pt;
font-family: arial;
}
CSS Comments
class=class_example>
ID Selector Syntax
Style Sheet
#id_example {
color : black
}
id=id_example>
{ color: black }
These declarations set font colors for the <p> element depending on
which class is defined in the element. If no class attribute is
specified, then the declaration for the <p> element of black is
applied.
Property Inheritance
Elements that are contained within other elements are said
to be children of the outer elements, and the outer
elements are referred to as parents of the nested elements.
This hierarchy of elements is applied to CSS in the form
of property inheritance.
Property inheritance means the properties that are defined
for parent elements are passed along to child elements,
unless the child element overrides the property.