CSS More Propertues
CSS More Propertues
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.
Border - A border that goes around the padding and content. The border is affected
by the background color
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
Example:
<html>
<head>
<style>
div
{
width:220px;
padding:10px;
border:5px solid gray;
margin:0px;
}
</style>
</head>
<body>
<img src="water.gif" width="250" height="250" />
<div>It is Good Background Pic.</div>
</body>
</html>
CSS - Borders
The border properties allow you to specify how the border of the box representing
an element should look. There are three properties of a border you can change
Examples:
<p style="border-width:4px; border-style:none;">
This is a border with none width.
</p>
<p style="border-width:4px; border-style:solid;">
This is a solid border.
</p>
<p style="border-width:4px; border-style:dashed;">
This is a dahsed border.
</p>
<p style="border-width:4px; border-style:double;">
This is a double border.
</p>
<p style="border-width:4px; border-style:groove;">
This is a groove border.
</p>
<p style="border-width:4px; border-style:ridge">
This is aridge border.
</p>
<p style="border-width:4px; border-style:inset;">
This is a inset border.
</p>
<p style="border-width:4px; border-style:outset;">
This is a outset border.
</p>
<p style="border-width:4px; border-style:hidden;">
This is a hidden border.
</p>
CSS Outlines
An outline is a line that is drawn around elements (outside the borders) to make
the element "stand out". The outline properties specify the style, color, and width
of an outline.
However, the outline property is different from the border property.
outline Property
Example:
<html>
<head>
<style>
p
{
border:1px solid red;
outline:green dotted thick;
}
</style>
</head>
<body>
<p>Supports the outline properties only</p>
</body>
</html>
outline-color Property
The outline-color property specifies the color of an outline.
Example:
p
{
outline-style:dotted;
outline-color:#00ff00;
}
outline-style Property
The outline-style property specifies the style of an outline.
Example:
p
{
outline-style:dotted;
}
outline-width Property
The outline-width specifies the width of an outline.
Example:
p
{
outline-style:dotted;
outline-width:5px;
}
CSS - Margins:
The margin property defines the space around an HTML element. It is possible to use
negative values to overlap content.
Example:
<html>
<head>
<style type='text/css'>
h5
{
margin:2cm 4cm 3cm 4cm
}
</style>
</head>
<body>
<p>A paragraph with no specified margins.</p>
<h5>A paragraph with specified margins.</h5>
<p>A paragraph with no specified margins.</p>
</body>
</html>
Example:
<html>
<head>
<style type='text/css'>
h5
{
margin-bottom:2cm;
}
</style>
</head>
<body>
<p>A paragraph with no specified margins.</p>
<h5>A paragraph with specified margins.</h5>
<p>A paragraph with no specified margins.</p>
</body>
</html>
CSS - Paddings
The padding property allows you to specify how much space should appear between the
content of an element and its border:
Example:
<html>
<head>
<style>
h4
{
padding:2cm;
}
h5
{
padding:0.5cm 3cm;
}
</style>
</head>
<body>
<h4>This text has equal padding on each side.</h4>
<h5>This text has a top and bottom padding of 0.5cm</h5>
</body>
</html>
CSS - Cursors:
The cursor property of CSS allows you to specify the type of cursor that should be
displayed to the user.
auto Shape of the cursor depends on the context area it is over.
crosshair A crosshair or plus sign
default An arrow
pointer A pointing hand
move The I bar
e-resize The cursor indicates that an edge of a box is to be moved
ne-resize The cursor indicates that an edge of a box is to be moved up
nw-resize The cursor indicates that an edge of a box is to be moved up
n-resize se-resize moved down and sw-resize moved down and left
s-resize moved down (south)
w-resize moved left (west)
text The I bar
wait An hour glass
help A question mark or balloon
Examples:
<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>
<div style="cursor:pointer">Pointer</div>
<div style="cursor:move">Move</div>
<div style="cursor:e-resize">e-resize</div>
<div style="cursor:ne-resize">ne-resize</div>
<div style="cursor:nw-resize">nw-resize</div>
<div style="cursor:n-resize">n-resize</div>
<div style="cursor:se-resize">se-resize</div>
<div style="cursor:sw-resize">sw-resize</div>
<div style="cursor:s-resize">s-resize</div>
<div style="cursor:w-resize">w-resize</div>
<div style="cursor:text">text</div>
<div style="cursor:wait">wait</div>
<div style="cursor:help">help</div>
Syntax
selector::pseudo-element
{
property:value;
}
Example:
<head>
<style>
p::first-line
{
color: #ff00ff;
font-variant: small-caps;
}
</style>
</head>
<body>
<p>You can use the ::first-line pseudo-element to add a special effect to the first
line of a text. Some more text. And even more, and more, and more, and more, and
more, and more, and more, and more, and more, and more, and more, and more.</p>
</body>
Example:
<head>
<style>
h1::before {
content: url(smiley.png);
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>The ::before pseudo-element inserts content before the content of an
element.</p>
</body>
Example:
<head>
<style>
h1::after {
content: url(smiley.png);
}
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>The ::after pseudo-element inserts content after the content of an element.</p>
</body>
Example:
<head>
<style>
::-moz-selection { /* Code for Firefox */
color: red;
background: yellow;
}
::selection {
color: red;
background: yellow;
}
</style>
</head>
<body>
<h1>Select some text on this page:</h1>
<p>This is a paragraph.</p>
<div>This is some text in a div element.</div>
</body>