Css Introduction
Css Introduction
CSS Syntax
A CSS rule consists of a selector and a declaration block.
The following example selects all <h1> tags and makes the content inside
red and centered.
h1 {/*selectorforheading1tags*/
color: red;/*maketheheadingsred#ff0000*/
textalign: center;/*centertheheadings*/
}
The id Selector
The id selector uses the id of an HTML element in the page.
An id should be unique within the page, and is used to select a
single, unique element.
Example: You can select the element with id=unique
#unique {
textalign: center;
color: red;
}
Style Sheet
2. Internal
Style Sheet
3. Inline
Styles
3. Inline Styles
If you want to add unique styling to a single element, you
can specify the CSS rules inline.
Simply use the style attribute and define all your CSS rules.
Examples:
<h1 style="color:blue;">
<img style="width:100px;height:100px"/>
<table style="width:100%">
CSS Text
Text Color
h1 {
color: #00ff00;
}
For simple colors you can use words like black, blue, red, orange etc. or
you can choose a color using a color picker such as:
http://www.w3schools.com/tags/ref_colorpicker.asp
Text Alignment
h1 {
textalign: center;/*center|right|justify*/
}
Text Shadow
h1 {
textshadow: 2px2px red;
}
CSS Font
In CSS, there are two types of font family names:
Generic family a group of fonts with a similar look (e.g. Serif,
Monospace)
Font Family a specific font family (e.g. Arial, Times New Roman)
The font-family property should hold several font family names as a
fallback system.
Start with the font you want, and end with a generic family. The browser
will choose your font based upon availability.
p {
fontfamily: "TimesNewRoman",Times,serif;
}
CSS Links
Links can be styled just like text
/*unvisitedlink*/
a:link {
color: #FF0000;
}
textdecoration: none;
/*visitedlink*/
a:visited {
color: #00FF00;
}
/*mouseoverlink*/
a:hover {
color: #FF00FF;
}
textdecoration: underline;
/*selectedlink themomentthelinkisclicked*/
a:active {
color: #0000FF;
}
CSS Background
You can change the background color of an HTML document or even use an image
for the background
Colors can be specified in a few different ways:
body {
backgroundcolor: #FF0000;/*HEXvalue*/
}
body {
backgroundcolor: rgb(255,0,0);/*RGBvalue*/
}
body {
backgroundcolor: red;/*name*/
}
You can also use an image
body {
backgroundimage: url("background.jpg");
}
CSS Lists
You can change the list item marker using the list-style-type
property.
ul {
liststyletype: circle;/*circle|square*/
}
ol {
liststyletype: upperroman;/*upperroman|loweralpha*/
}
CSS Tables
You can specify a border using the border property
table,th,td {
border: 1pxsolidblack;
}
Choose between single border or separated with the border-collapse property.
table {
bordercollapse: collapse;
}
Change the height and width:
table {
width: 100%;
}
th {
height: 50px;
}
CSS Images
The height and width properties are used to set the height and width of an
element.
img {
height: 100px;
width: 50px;
}
You can use the clear property to control the behavior of floating elements.
div {
clear: left;
}