CSS1 S
CSS1 S
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "margin: 15px; border:1px solid black;">
all four margins will be 15px
</p>
top and bottom margin will be 10px, left and right margin will be 2% of the total width of the document.
top margin will be 10px, left and right margin will be 2% of the total width of the document,
bottom margin will be -10px
top margin will be 10px, right margin will be 2% of the total width of the document, bottom
margin will be -10px, left margin will be set by the browser
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "margin-bottom: 15px; border:1px solid black;">
This is a paragraph with a specified bottom margin
</p>
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "margin-top: 15px; border:1px solid black;">
This is a paragraph with a specified top margin
</p>
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "margin-left: 15px; border:1px solid black;">
This is a paragraph with a specified left margin
</p>
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "margin-right: 15px; border:1px solid black;">
This is a paragraph with a specified right margin
</p>
<p style = "margin-right: 5%; border:1px solid black;">
This is another paragraph with a specified right margin in
percent </p>
</body>
</html>
CSS - Lists
Now, we will see how to use these properties with examples.
Here are the values which can be used for an unordered list −
Sr.No. Value & Description
1 none
NA
2 disc (default)
A filled-in circle
3 circle
An empty circle
4 square
A filled-in square
Here are the values, which can be used for an ordered list −
Value Description Example
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<ul style = "list-style-
type:circle;"> <li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
Maths
Social Science
Physics
1. Maths
2. Social Science
3. Physics
a. Maths
b. Social Science
c. Physics
i. Maths
ii. Social Science
iii. Physics
1 none
NA
2 inside
If the text goes onto a second line, the text will wrap underneath the marker.
It will also appear indented to where the text would have started if the list had
a value of outside.
3 outside
If the text goes onto a second line, the text will be aligned with the start of
the first line (to the right of the bullet).
Here is an example −
Live Demo
<html>
<head>
</head>
ssssssssssssssssssssssssssss
<body>
<ul style = "list-style-type:circle; list-stlye-position:outside;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<ul>
<li style = "list-style-image: url(/images/bullet.gif);">Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
<ol>
<li style = "list-style-image: url(/images/bullet.gif);">Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>
</body>
</html>
Maths
Social Science
Physics
Maths
2. Social Science
3. Physics
ssssssssssssssssssssssssssssssssss
The list-style allows you to specify all the list properties into a single
expression. These properties can appear in any order.
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<ul style = "list-style: inside square;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
Maths
Social Science
Physics
A. Maths
B. Social Science
C. Physics
sssssssssssss
Here is an example −
<html>
<head>
</head>
<body>
<ul style = "list-style: inside square; marker-offset:2em;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ul>
<ol style = "list-style: outside upper-alpha; marker-offset:2cm;">
<li>Maths</li>
<li>Social Science</li>
<li>Physics</li>
</ol>
</body>
</html>
Maths
Social Science
Physics
A. Maths
B. Social Science
C. Physics
CSS - Paddings
The padding serves as shorthand for the preceding properties.Now, we will see how
sssssssssssssssssssssssssssssssssssssssssssss
The padding-bottom property sets the bottom padding (space) of an element. This
can take a value in terms of length of %.
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "padding-bottom: 15px; border:1px solid
black;"> This is a paragraph with a specified
bottom padding
</p>
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "padding-top: 15px; border:1px solid black;">
This is a paragraph with a specified top padding
</p>
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "padding-left: 15px; border:1px solid black;">
This is a paragraph with a specified left padding
</p>
ssssssssssssssssssssssssssssssssssss
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "padding-right: 15px; border:1px solid black;"> This is a
paragraph with a specified right padding
</p>
sssssssssssssssssssssssssssssssssssssssssss
s
ssssssssssssssssss
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "padding: 15px; border:1px solid black;">
all four padding will be 15px
</p>
top and bottom padding will be 10px, left and right padding will be 2% of the total width of the
document.
top padding will be 10px, left and right padding will be 2% of the total width of the document,
bottom padding will be 10px
top padding will be 10px, right padding will be 2% of the total width of the document, bottom
padding and top padding will be 10px
CSS - Cursors
1 auto
Shape of the cursor depends on the context area it is over. For example an I over
text, a hand over a link, and so on...
2 crosshair
A crosshair or plus sign
3 default
An arrow
4 pointer
A pointing hand (in IE 4 this value is hand)
5 move
The I bar
6 e-resize
The cursor indicates that an edge of a box is to be moved right (east)
7 ne-resize
The cursor indicates that an edge of a box is to be moved up and right (north/east)
8 nw-resize
The cursor indicates that an edge of a box is to be moved up and left (north/west)
9 n-resize
The cursor indicates that an edge of a box is to be moved up (north)
10 se-resize
The cursor indicates that an edge of a box is to be moved down and right
(south/east)
11 sw-resize
The cursor indicates that an edge of a box is to be moved down and left (south/west)
1 s-resize
2 The cursor indicates that an edge of a box is to be moved down (south)
1 w-resize
3 The cursor indicates that an edge of a box is to be moved left (west)
14 text
The I bar
15 wait
An hour glass
1 help
6 A question mark or balloon, ideal for use over help buttons
17 <url>
The source of a cursor image file
NOTE − You should try to use only these values to add helpful information for
users, and in places, they would expect to see that cursor. For example, using the
crosshair when someone hovers over a link can confuse visitors.
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p>Move the mouse over the words to see the cursor
change:</p>
<div style = "cursor:auto">Auto</div>
<div style = "cursor:crosshair">Crosshair</div>
<div style = "cursor:default">Default</div>
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
Move the mouse over the words to see the cursor change:
Auto
Crosshair
Default
Pointer
Move
e-resize
ne-resize
nw-resize
n-resize
se-resize
sw-resize
s-resize
w-resize
text
wait
help
CSS - Outlines
The outline-width property is used to set the width of the outline.
The outline-style property is used to set the line style for the outline. The outline-
color property is used to set the color of the outline.
The outline property is used to set all the above three properties in a single
statement.
ssssssssssssssssssssssssssssssssssssssss
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "outline-width:thin; outline-style:solid;">
This text is having thin outline.
</p>
<br />
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "outline-width:thin; outline-style:solid;">
This text is having thin solid outline.
</p>
sssssssssssssssssssssssssssssssss
<br />
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "outline-width:thin; outline-style:solid;outline-color:red">
This text is having thin solid red outline.
</p>
<br />
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "outline:thin solid red;">
This text is having thin solid red outline.
</p>
<br />
CSS - Dimension
The max-width property is used to set the maximum width that a box can be. The
min-width property is used to set the minimum width that a box can be.
Here is an example −
Live Dem
ssssssssssssssssssssssssssss
<html>
<head>
</head>
<body>
<p style = "width:400px; height:100px; border:1px solid red;
padding:5px; margi This paragraph is 400pixels wide and 100 pixels
high
</p>
</body>
</html>
It will produce the following result −
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "width:400px; height:100px; border:1px solid red;
padding:5px; margi This paragraph is 400pixels wide and 100 pixels
high and here line height is This paragraph is 400 pixels wide and
100 pixels high and here line height i </p>
ssssssssssssssssssssssssssssssssssss
</body>
</html>
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "width:400px; max-height:10px; border:1px solid red;
padding:5px; ma This paragraph is 400px wide and max height is 10px
This paragraph is 400px wide and max height is 10px
This paragraph is 400px wide and max height is 10px
This paragraph is 400px wide and max height is 10px
</p>
<br>
<br>
<br>
<img alt = "logo" src = "/css/images/logo.png" width = "195" height =
"84" /> </body>
</html>
sssssssssssssssssssssssssssssssssssssssssssss
It will produce the following result −
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "width:400px; min-height:200px; border:1px solid red;
padding:5px; m This paragraph is 400px wide and min height is 200px
This paragraph is 400px wide and min height is 200px
This paragraph is 400px wide and min height is 200px
This paragraph is 400px wide and min height is 200px
</p>
<img alt = "logo" src = "/css/images/logo.png" width = "95" height
= "84" /> </body>
</html>
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "max-width:100px; height:200px; border:1px solid red;
padding:5px; m This paragraph is 200px high and max width is 100px
This paragraph is 200px high and max width is 100px
This paragraph is 200px high and max width is 100px
This paragraph is 200px high and max width is 100px
This paragraph is 200px high and max width is 100px
</p>
<img alt = "logo" src = "/images/css.gif" width = "95" height
= "84" /> </body>
</html>
This will produce following result −
This paragraph
is 200px high
and max width
is 100px This
paragraph is
200px high and
max width is
100px This
paragraph is
200px high and
max width is
100px This
paragraph is
200px high and
max width is
100px This
paragraph is
200px high and
max width is
100px
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p style = "min-width:400px; height:100px; border:1px solid red;
padding:5px; m This paragraph is 100px high and min width is 400px
This paragraph is 100px high and min width is 400px
</p>
<img alt = "logo" src = "/css/images/css.gif" width = "95" height =
"84" />
ssssssssssssssssssssssssssss
</body>
</html>
This paragraph is 100px high and min width is 400px This paragraph is 100px high and min width is 400px
CSS - Scrollbars
1 visible
Allows the content to overflow the borders of its containing element.
2 hidden
The content of the nested element is simply cut off at the border of the
containing element and no scrollbars is visible.
3 scroll
The size of the containing element does not change, but the scrollbars are added
to allow the user to scroll to see the content.
4 auto
The purpose is the same as scroll, but the scrollbar will be shown only if the
content does overflow.
Here is an example –
Sssssssssssssssssssssssssssssssssss
<html>
<head>
<style type =
"text/css"> .scroll
{
sssssssssssssssssssssssssssssssssssssss
display:block;
border: 1px solid red;
padding:5px;
margin-top:5px;
width:300px;
height:50px;
overflow:scroll;
}
.auto {
display:block;
border: 1px solid red;
padding:5px;
margin-top:5px;
width:300px;
height:50px;
overflow:auto;
}
</style>
</head>
<body>
<p>Example of scroll value:</p>
<div class = "scroll">
I am going to keep lot of content here just to show you how
scrollbars works if there is an overflow in an element box. This
provides your horizontal as well as vertical scrollbars. </div>
<br />
CSS - Visibility
1 visible
The box and its contents are shown to the user.
2 hidden
The box and its content are made invisible, although they still affect the layout of
the page.
3 collapse
This is for use only with dynamic table columns and row effects.
Here is an example −
Live Demo
<html>
<head>
</head>
<body>
<p>
This paragraph should be visible i
sssssssssssssssssssssssssssssssssssssssssssssssssssss
n normal way.
</p>
sssssssssssssssssssssssssssssssssssssssssssssssssssssss
</body>
</html>
CSS - Positioning
Move Up - Use a negative value for top.
Move Down - Use a positive value for top.
NOTE − You can use bottom or right values as well in the same way as top and left.
Live Demo
<html>
<head>
</head>
<body>
<div style = "position:relative; left:80px; top:2px; background-
color:yellow;"> This div has relative positioning.
</div>
</body>
</html>
sssssssssssssssssssssssssssssssssssssssssssssss
Absolute Positioning
An element with position: absolute is positioned at the specified coordinates
relative to your screen top-left corner.
You can use two values top and left along with the position property to move
an HTML element anywhere in the HTML document.
NOTE − You can use bottom or right values as well in the same way as
Live Demo
<html>
<head>
</head>
<body>
<div style = "position:absolute; left:80px; top:20px; background-
color:yellow;" This div has absolute positioning.
</div>
</body>
</html>
This div has absolute positioning.
Fixed Positioning
Fixed positioning allows you to fix the position of an element to a particular spot on
the page, regardless of scrolling. Specified coordinates will be relative to the
browser window.
You can use two values top and left along with the position property to move
an HTML element anywhere in the HTML document.
NOTE − You can use bottom or right values as well in the same way as
Live Demo
<html>
<head>
</head>
<body>
<div style = "position:fixed; left:80px; top:20px; background-
color:yellow;"> This div has fixed positioning.
</div>
</body>
</html>