0% found this document useful (0 votes)
729 views

All CSS Background Properties

The document summarizes CSS properties related to backgrounds, text formatting, and fonts. It provides tables that list CSS properties, descriptions, possible values, and the CSS version in which each was defined. For backgrounds, properties like background-color, background-image, and background-position are described. For text, properties such as color, line-height, text-align, and text-decoration are listed. Font properties define font families, styles, sizes and other text attributes. Examples are given to demonstrate some properties.

Uploaded by

hush101
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
729 views

All CSS Background Properties

The document summarizes CSS properties related to backgrounds, text formatting, and fonts. It provides tables that list CSS properties, descriptions, possible values, and the CSS version in which each was defined. For backgrounds, properties like background-color, background-image, and background-position are described. For text, properties such as color, line-height, text-align, and text-decoration are listed. Font properties define font families, styles, sizes and other text attributes. Examples are given to demonstrate some properties.

Uploaded by

hush101
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

All CSS Background Properties :-

Property Description Values CSS


background-color
background-image
Sets all the background background-repeat
background 1
properties in one declaration background-attachment
background-position
inherit
Sets whether a background scroll
background-
image is fixed or scrolls with fixed 1
attachment
the rest of the page inherit
color-rgb
color-hex
Sets the background color of an
background-color color-name 1
element
transparent
inherit
url(URL)
Sets the background image for
background-image none 1
an element
inherit
left top
left center
left bottom
right top
right center
Sets the starting position of a right bottom
background-position 1
background image center top
center center
center bottom
x% y%
xpos ypos
inherit
repeat
repeat-x
Sets if/how a background image
background-repeat repeat-y 1
will be repeated
no-repeat
inherit

Example
body
{
background-image:url('img_tree.png');
background-repeat:no-repeat;
background-position:right top;
}
Example
h1 {background-color:#6495ed;}
p {background-color:#e0ffff;}
div {background-color:#b0c4de;}

All CSS Text Properties :-


The number in the "CSS" column indicates in which CSS version the property is defined

Property Description Values CSS


color Sets the color of a text color 1
ltr
direction Sets the text direction 2
rtl
normal
number
line-height Sets the distance between lines 1
length
%
Increase or decrease the space between normal
letter-spacing 1
characters length
left
right
text-align Aligns the text in an element 1
center
justify
none
underline
text-decoration Adds decoration to text overline 1
line-through
blink
length
text-indent Indents the first line of text in an element 1
%
none
text-shadow   color  
length
none
capitalize
text-transform Controls the letters in an element 1
uppercase
lowercase
normal
unicode-bidi   embed 2
bidi-override
vertical-align Sets the vertical alignment of an element baseline 1
sub
super
top
text-top
middle
bottom
text-bottom
length
%
normal
Sets how white space inside an element is
white-space pre 1
handled
nowrap
normal
word-spacing Increase or decrease the space between words 1
length

Example of text alignment:


h1 {text-align:center;}
p.date {text-align:right;}
p.main {text-align:justify;}

Example of text decoration:


h1 {text-decoration:overline;}
h2 {text-decoration:line-through;}
h3 {text-decoration:underline;}
h4 {text-decoration:blink;}

CSS Font :-

CSS font properties define the font family, boldness, size, and the style of a text.

Difference Between Serif and Sans-serif Fonts

On computer screens, sans-serif fonts are considered easier to read than serif fonts.
CSS Font Families
In CSS, there are two types of font family names:

 generic family - a group of font families with a similar look (like "Serif" or
"Monospace")
 font family - a specific font family (like "Times New Roman" or "Arial")

Generic family Font family Description


Times New
Serif fonts have small lines at the ends on
Serif Roman some characters
Georgia
Sans-serif
Arial "Sans" means without - these fonts do not
Verdana have the lines at the ends of characters

Monospace
Courier New All monospace characters have the same
Lucida Console width

Example of Font Family


<html>

<head>

<style type="text/css">

p.serif{font-family:"Times New Roman",Times,serif;}

p.sansserif{font-family:Arial,Helvetica,sans-serif;}

</style>

</head>

<body>

<h1>CSS font-family</h1>

<p class="serif">This is a paragraph, shown in the Times New Roman font.</p>

<p class="sansserif">This is a paragraph, shown in the Arial font.</p>

</body>

</html>
O/P:

CSS font-family

This is a paragraph, shown in the Times New Roman font.

This is a paragraph, shown in the Arial font.

All CSS Font Properties


The number in the "CSS" column indicates in which CSS version the property is defined

CS
Property Description Values
S
font-style
font-variant
font-weight
font-size/line-height
font-family
Sets all the font properties in one caption
font 1
declaration icon
menu
message-box
small-caption
status-bar
inherit
family-name
font-family Specifies the font family for text generic-family 1
inherit
xx-small
x-small
small
medium
large
x-large
font-size Specifies the font size of text 1
xx-large
smaller
larger
length
%
inherit
normal
italic
font-style Specifies the font style for text 1
oblique
inherit
normal
Specifies whether or not a text should
font-variant small-caps 1
be displayed in a small-caps font
inherit
font-weight Specifies the weight of a font normal 1
bold
bolder
lighter
100
200
300
400
500
600
700
800
900
inherit

Styling Links
Links can be styled with any CSS property (e.g. color, font-family, background, etc.).

Special for links are that they can be styled differently depending on what state they are in.

The four links states are:

 a:link - a normal, unvisited link


 a:visited - a link the user has visited
 a:hover - a link when the user mouses over it
 a:active - a link the moment it is clicked

Example
a:link {color:#FF0000;}      /* unvisited link */
a:visited {color:#00FF00;}  /* visited link */
a:hover {color:#FF00FF;}  /* mouse over link */
a:active {color:#0000FF;}  /* selected link */

Common Link Styles


In the example above the link changes color depending on what state it is in.

Lets go through some of the other common ways to style links:

Text Decoration
The text-decoration property is mostly used to remove underlines from links:
Example
a:link {text-decoration:none;}
a:visited {text-decoration:none;}
a:hover {text-decoration:underline;}
a:active {text-decoration:underline;}

CSS Lists
The CSS list properties allow you to:

 Set different list item markers for ordered lists


 Set different list item markers for unordered lists
 Set an image as the list item marker

List
In HTML, there are two types of lists:

 unordered lists - the list items are marked with bullets


 ordered lists - the list items are marked with numbers or letters

With CSS, lists can be styled further, and images can be used as the list item marker.

Different List Item Markers


The type of list item marker is specified with the list-style-type property:

Example
ul.a {list-style-type: circle;}
ul.b {list-style-type: square;}

ol.c {list-style-type: upper-roman;}


ol.d {list-style-type: lower-alpha;}

ome of the property values are for unordered lists, and some for ordered lists.

Values for Unordered Lists


Value Description
none No marker
disc Default. The marker is a filled circle
circle The marker is a circle
square The marker is a square

Values for Ordered Lists


Value Description
armenian The marker is traditional Armenian numbering
decimal The marker is a number
decimal-leading-zero The marker is a number padded by initial zeros (01, 02, 03, etc.)
georgian The marker is traditional Georgian numbering (an, ban, gan, etc.)
lower-alpha The marker is lower-alpha (a, b, c, d, e, etc.)
lower-greek The marker is lower-greek (alpha, beta, gamma, etc.)
lower-latin The marker is lower-latin (a, b, c, d, e, etc.)
lower-roman The marker is lower-roman (i, ii, iii, iv, v, etc.)
upper-alpha The marker is upper-alpha (A, B, C, D, E, etc.) 
upper-latin The marker is upper-latin (A, B, C, D, E, etc.)
upper-roman The marker is upper-roman (I, II, III, IV, V, etc.)

An Image as The List Item Marker


To specify an image as the list item marker, use the list-style-image property:

Example
ul
{
list-style-image: url('sqpurple.gif');
}

The example above does not display equally in all browsers. IE and Opera will display the image-
marker a little bit higher than Firefox, Chrome, and Safari.

If you want the image-marker to be placed equally in all browsers, a crossbrowser solution is
explained below.

Crossbrowser Solution
The following example displays the image-marker equally in all browsers:

Example
ul
{
list-style-type: none;
padding: 0px;
margin: 0px;
}
li
{
background-image: url(sqpurple.gif);
background-repeat: no-repeat;
background-position: 0px 5px;
padding-left: 14px;
}

List - Shorthand property


It is also possible to specify all the list properties in one, single property. This is called a
shorthand property.

The shorthand property used for lists, is the list-style property:

Example
ul
{
list-style: square url("sqpurple.gif");
}

When using the shorthand property, the order of the values are:

 list-style-type
 list-style-position (for a description, see the CSS properties table below)
 list-style-image

It does not matter if one of the values above are missing, as long as the rest are in the
specified order.

All CSS List Properties


The number in the "CSS" column indicates in which CSS version the property is defined

Property Description Values CSS


list-style-type
Sets all the properties for a list in one list-style-position
list-style 1
declaration list-style-image
inherit
URL
list-style-image Specifies an image as the list-item marker none 1
inherit
inside
Specifies if the list-item markers should
list-style-position outside 1
appear inside or outside the content flow
inherit
none
disc
circle
square
decimal
decimal-leading-zero
armenian
georgian
list-style-type Specifies the type of list-item marker 1
lower-alpha
upper-alpha
lower-greek
lower-latin
upper-latin
lower-roman
upper-roman
inherit

CSS Tables:-

Table Borders
To specify table borders in CSS, use the border property.

The example below specifies a black border for table, th, and td elements:

Example
table, th, td
{
border: 1px solid black;
}

Collapse Borders
The border-collapse property sets whether the table borders are collapsed into a single border
or separated:

Example
table
{
border-collapse:collapse;
}
table,th, td
{
border: 1px solid black;
}

Table Width and Height


Width and height of a table is defined by the width and height properties.

The example below sets the width of the table to 100%, and the height of the th elements to
50px:

Example
table
{
width:100%;
}
th
{
height:50px;
}

Table Text Alignment


The text in a table is aligned with the text-align and vertical-align properties.

The text-align property sets the horizontal alignment, like left, right, or center:

Example
td
{
text-align:right;
}

The vertical-align property sets the vertical alignment, like top, bottom, or middle:

Example
td
{
height:50px;
vertical-align:bottom;
}

Table Padding
To control the space between the border and content in a table, use the padding property on td
and th elements:

Example
td
{
padding:15px;
}

Table Color
The example below specifies the color of the borders, and the text and background color of th
elements:

Example
table, td, th
{
border:1px solid green;
}
th
{
background-color:green;
color:white;
}
The CSS Box Model
All HTML elements can be considered as boxes. In CSS, the term "box model" is used when
talking about design and layout.

The CSS box model is essentially a box that wraps around HTML elements, and it consists
of: margins, borders, padding, and the actual content.

The box model allows us to place a border around elements and space elements in relation to
other elements.

The image below illustrates the box model:

Explanation of the different parts:

 Margin - Clears an area around the border. The margin does not have a background color, it
is completely transparent
 Border - A border that goes around the padding and content. The border is affected by the
background color of the box
 Padding - Clears an area around the content. The padding is affected by the background
color of the box
 Content - The content of the box, where text and images appear

In order to set the width and height of an element correctly in all browsers, you need to know
how the box model works.
Width and Height of an Element
Important: When you specify the width and height properties of an element with CSS, you
are just setting the width and height of the content area. To know the full size of the element,
you must also add the padding, border and margin.

The total width of the element in the example below is 300px:

width:250px;
padding:10px;
border:5px solid gray;
margin:10px;

Let's do the math:


250px (width)
+ 20px (left and right padding)
+ 10px (left and right border)
+ 20px (left and right margin)
= 300px

Imagine that you only had 250px of space. Let's make an element with a total width of
250px:

Example
width:220px;
padding:10px;
border:5px solid gray;
margin:0px;

The total width of an element should always be calculated like this:

Total element width = width + left padding + right padding + left border + right border + left
margin + right margin

The total height of an element should always be calculated like this:

Total element height = height + top padding + bottom padding + top border + bottom border
+ top margin + bottom margin

Browsers Compatibility Issue


If you tested the previous example in Internet Explorer, you saw that the total width was not
exactly 250px.
IE includes padding and border in the width, when the width property is set, unless a
DOCTYPE is declared.

To fix this problem, just add a DOCTYPE to the code:

Example
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
div.ex
{
width:220px;
padding:10px;
border:5px solid gray;
margin:0px;
}
</style>
</head>

CSS Border

CSS Border Properties


The CSS border properties allow you to specify the style and color of an element's border.

Border Style
The border-style property specifies what kind of border to display.

None of the border properties will have ANY effect unless the border-style property is set!

Border-style values:
none: Defines no border
dotted: Defines a dotted border

dashed: Defines a dashed border

solid: Defines a solid border

double: Defines two borders. The width of the two borders are the same as the border-width
value

groove: Defines a 3D grooved border. The effect depends on the border-color value

ridge: Defines a 3D ridged border. The effect depends on the border-color value

inset: Defines a 3D inset border. The effect depends on the border-color value

outset: Defines a 3D outset border. The effect depends on the border-color value

Border Width
The border-width property is used to set the width of the border.

The width is set in pixels, or by using one of the three pre-defined values: thin, medium, or
thick.

Note: The "border-width" property does not work if it is used alone. Use the "border-style"
property to set the borders first.
Example
p.one
{
border-style:solid;
border-width:5px;
}
p.two
{
border-style:solid;
border-width:medium;
}

Border Color
The border-color property is used to set the color of the border. The color can be set by:

 name - specify a color name, like "red"


 RGB - specify a RGB value, like "rgb(255,0,0)"
 Hex - specify a hex value, like "#ff0000"

You can also set the border color to "transparent".

Note: The "border-color" property does not work if it is used alone. Use the "border-style"
property to set the borders first.

Example
p.one
{
border-style:solid;
border-color:red;
}
p.two
{
border-style:solid;
border-color:#98bf21;
}
Border - Individual sides
In CSS it is possible to specify different borders for different sides:

Example
p
{
border-top-style:dotted;
border-right-style:solid;
border-bottom-style:dotted;
border-left-style:solid;
}

The example above can also be set with a single property:

Example
border-style:dotted solid;

The border-style property can have from one to four values.

 border-style:dotted solid double dashed;


o top border is dotted
o right border is solid
o bottom border is double
o left border is dashed.
 border-style:dotted solid double;
o top border is dotted
o right and left borders are solid
o bottom border is double.
 border-style:dotted solid;
o top and bottom borders are dotted
o right and left borders are solid
 border-style:dotted;
o all four borders are dotted

The border-style property is used in the example above. However, it also works with border-
width and border-color.
Border - Shorthand property
As you can see from the examples above, there are many properties to consider when dealing
with borders.

To shorten the code, it is also possible to specify all the border properties in one property.
This is called a shorthand property.

The shorthand property for the border properties is "border":

Example
border:5px solid red;

When using the border property, the order of the values are:

 border-width
 border-style
 border-color

It does not matter if one of the values above are missing (although, border-style is required),
as long as the rest are in the specified order.

More Examples
All the top border properties in one declaration
This example demonstrates a shorthand property for setting all of the properties for the top
border in one declaration.

Set the style of the bottom border


This example demonstrates how to set the style of the bottom border.

Set the width of the left border


This example demonstrates how to set the width of the left border.

Set the color of the four borders


This example demonstrates how to set the color of the four borders. It can have from one to
four colors.

Set the color of the right border


This example demonstrates how to set the color of the right border.
All CSS Border Properties
The number in the "CSS" column indicates in which CSS version the property is defined
(CSS1 or CSS2).

Property Description Values CSS

border-width
Sets all the border properties in one
border border-style 1
declaration
border-color

border-bottom-width
Sets all the bottom border properties in one
border-bottom border-bottom-style 1
declaration
border-bottom-color

border-bottom-color Sets the color of the bottom border border-color 2

border-bottom-style Sets the style of the bottom border border-style 2

border-bottom-width Sets the width of the bottom border border-width 1

color_name
hex_number
border-color Sets the color of the four borders rgb_number 1
transparent
inherit

border-left-width
Sets all the left border properties in one
border-left border-left-style 1
declaration
border-left-color

border-left-color Sets the color of the left border border-color 2

border-left-style Sets the style of the left border border-style 2

border-left-width Sets the width of the left border border-width 1

border-right-width
Sets all the right border properties in one
border-right border-right-style 1
declaration
border-right-color

border-right-color Sets the color of the right border border-color 2

border-right-style Sets the style of the right border border-style 2

border-right-width Sets the width of the right border border-width 1

border-style Sets the style of the four borders none 1


hidden
dotted
dashed
solid
double
groove
ridge
inset
outset
inherit

border-top-width
Sets all the top border properties in one
border-top border-top-style 1
declaration
border-top-color

border-top-color Sets the color of the top border border-color 2

border-top-style Sets the style of the top border border-style 2

border-top-width Sets the width of the top border border-width 1

thin
medium
border-width Sets the width of the four borders thick 1
length
inherit

CSS Outlines
An outline is a line that is drawn around elements, outside the border edge, to make the
element "stand out".

The outline properties specifies the style, color, and width of an outline.

All CSS Outline Properties


The number in the "CSS" column indicates in which CSS version the property is defined
(CSS1 or CSS2).

Property Description Values CSS

outline-color
outline-style
outline Sets all the outline properties in one declaration 2
outline-width
inherit

outline-color Sets the color of an outline color_name 2


hex_number
rgb_number
invert
inherit

none
dotted
dashed
solid
double
outline-style Sets the style of an outline 2
groove
ridge
inset
outset
inherit

thin
medium
outline-width Sets the width of an outline thick 2
length
inherit

he CSS margin properties define the space around elements.

Margin
The margin clears an area around an element (outside the border). The margin does not have
a background color, and is completely transparent.

The top, right, bottom, and left margin can be changed independently using separate
properties. A shorthand margin property can also be used, to change all margins at once.

Possible Values
Value Description

The browser sets the margin.


auto
The result of this is dependant of the browser

length Defines a fixed margin (in pixels, pt, em, etc.)

% Defines a margin in % of the containing element

It is possible to use negative values, to overlap content.


Margin - Individual sides
In CSS, it is possible to specify different margins for different sides:

Margin - Shorthand property


To shorten the code, it is possible to specify all the margin properties in one property. This is
called a shorthand property.

The shorthand property for all the margin properties is "margin":

Example
margin:100px 50px;

The margin property can have from one to four values.

 margin:25px 50px 75px 100px;


o top margin is 25px
o right margin is 50px
o bottom margin is 75px
o left margin is 100px

 margin:25px 50px 75px;


o top margin is 25px
o right and left margins are 50px
o bottom margin is 75px

 margin:25px 50px;
o top and bottom margins are 25px
o right and left margins are 50px

 margin:25px;
o all four margins are 25px

More Examples
Set the top margin of a text using a cm value
This example demonstrates how to set the top margin of a text using a cm value.

Set the bottom margin of a text using a percent value


This example demonstrates how to set the bottom margin of a text using a percent value.

All CSS Margin Properties


The number in the "CSS" column indicates in which CSS version the property is defined
(CSS1 or CSS2).

Property Description Values CSS

margin-top
A shorthand property for setting the margin margin-right
margin 1
properties in one declaration margin-bottom
margin-left

auto
margin-bottom Sets the bottom margin of an element length 1
%

auto
margin-left Sets the left margin of an element length 1
%

auto
margin-right Sets the right margin of an element length 1
%

auto
margin-top Sets the top margin of an element length 1
%

CSS Padding

The CSS padding properties define the space between the element border and the element
content.

Padding
The padding clears an area around the content (inside the border) of an element. The padding
is affected by the background color of the element.
The top, right, bottom, and left padding can be changed independently using separate
properties. A shorthand padding property can also be used, to change all paddings at once.

Possible Values
Value Description

length Defines a fixed padding (in pixels, pt, em, etc.)

% Defines a padding in % of the containing element

Padding - Individual sides


In CSS, it is possible to specify different padding for different sides:

Example
padding-top:25px;
padding-bottom:25px;
padding-right:50px;
padding-left:50px;

Padding - Shorthand property


To shorten the code, it is possible to specify all the padding properties in one property. This is
called a shorthand property.

The shorthand property for all the padding properties is "padding":

Example
padding:25px 50px;

All CSS Padding Properties


The number in the "CSS" column indicates in which CSS version the property is defined
(CSS1 or CSS2).

Property Description Values CSS

padding-top
A shorthand property for setting all the padding padding-right
padding 1
properties in one declaration padding-bottom
padding-left

length
padding-bottom Sets the bottom padding of an element 1
%

length
padding-left Sets the left padding of an element 1
%

length
padding-right Sets the right padding of an element 1
%

length
padding-top Sets the top padding of an element 1
%

You might also like