Margin Property
It allows us to define the space around element of HTML document. We use following properties to set margin of element.
- margin
- margin-bottom
- margin-top
- margin-left
- margin-right
<html>
<head>
<style>
h1 {
margin-top: 50px;
margin-bottom: 100px;
}
p {
margin-left: 75px;
margin-right: 75px;
}
</style>
</head>
<body>
<h1>Margin example</h1>
<p>This is a normal paragraph of text.</p>
</body>
</html>
Output of above code- If one value is specified, applied to all four sides.
- If two values are specified, the first value is applied to the top and bottom side, and the second value is applied to the right and left side of the element's box.
- If three values are specified, the first value is applied to the top, second value is applied to right and left side, and the last value is applied to the bottom.
- If four values are specified, they are applied to the top, right, bottom and the left side of the element's box respectively in the specified order.
h1 { margin: 30px; /* apply to all four sides */ } p { margin: 20px 70px; /* vertical | horizontal */ } div { margin: 20px 50px 70px; /* top | horizontal | bottom */ } hr { margin: 20px 50px 70px 90px; /* top | right | bottom | left */ }
Example for mouseover with span
Mouse over the words to change the cursor. Place the mouse pointer on following word for effect.
autocrosshair
default
e-resize
help
move
n-resize
ne-resize
nw-resize
pointer
progress
s-resize
se-resize
sw-resize
text
w-resize
wait
Pseudo-elements
A pseudo-class is used to define a special state of an element.
Features
● Special-case selectors
● Anchors: Style an element when a user mouses over it, Style visited and unvisited links differently, Style an element when it gets focus.
a:hover
a:visited
a:active
a:link
Example for above pseudo-elements
Output
This is a link
When you will place mouse pointer on link then it will show effect.
Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective.
Note: a:active MUST come after a:hover in the CSS definition in order to be effective.
Classes:
If need to use different styles in one webpage, use classes. Define below code in style tag.
Call above class in HTML using following code.
<p class=“black”>This sentence is in black</p>
<p class=“blue”>This sentence is in blue</p>
0 Comments