- CSS Properties in HTML: Level-1
CSS bottom Property example
The CSS bottom property is used to offset an element's bottom position. It moves the element upward and the position property of the element determines the behavior of the placement it gets.
<style type="text/css">
#div1
{
background: #B1D8E2;
border: #3E95AE 2px dashed;
width: 250px;
height: 125px;
margin-top: 40px;
}
#div2
{
bottom: 15px;
left: 10px;
position: relative;
background: #FFE8B7;
border: #E19D00 2px dashed;
width: 140px;
height: 20px;
}
</style>
<div id="div1">
<div id="div2">
my div content ...</div>
my div content ...
</div>
CSS caption-side Property example
The CSS caption-side property is used to specify the position of a caption element in relation to its table element.
<!DOCTYPE html>
<style type="text/css">
#myTable
{
color: red;
}
#myTable td
{
color: Green;
}
#myTable caption
{
caption-side: bottom;
text-align: right;
font-size: 12px;
color: Red;
}
</style>
<table id="myTable" border="1">
<caption>
My Favorite Flavors</caption>
<tr>
<td>
Chocolate
</td>
<td>
Strawberry
</td>
<td>
Vanilla
</td>
</tr>
</table>
CSS content Property example
The CSS content property is used to generate content to the document when using CSS selectors that are intended to generate or replace content in the document. ::before and ::after are two such selectors.
Specify a single value or a space-separated list of values to be generated.
<!DOCTYPE html>
<style type="text/css">
.myClass::before
{
content: url(m5.jpg) " My ";
}
.myClass::after
{
content: "'s " attr(title) " section";
}
</style>
<h3 class="myClass" title="cool">
content</h3>
<h3 class="myClass" title="sweet">
content</h3>
<h3 class="myClass" title="lucious">
content</h3>
CSS absolute-position Property example
absolute
Allows the offset properties to apply to the element. The element will scroll with other content on the page. This setting takes the element out of its normal flow in the document.
<style type="text/css">
#container
{
border: #999 1px dashed;
height: 100px;
}
#container div
{
position: absolute;
background: #FFD5FF;
border: #F0F 1px solid;
padding: 10px;
width: 20px;
height: 20px;
}
#div1
{
top: 20px;
left: 20px;
}
#div2
{
top: 40px;
left: 40px;
}
#div3
{
top: 60px;
left: 60px;
}
</style>
<div id="container">
<div id="div1">
A</div>
<div id="div2">
B</div>
<div id="div3">
C</div>
</div>
CSS box-shadow Property example
The CSS box-shadow property is used to render shadows for content containers (boxes). Each distinct shadow can get up to 4 parameters and an optional "inset" keyword.
You can create a comma-separated list of distinct shadows that will apply under the same box to create various looking effects, as well as setting shadows to "inset" for embossing and engraving effects.
specify shadow parameters
Example: "inset 1px 2px 3px #000"
The optional inset keyword places a shadow inside of the box.
The first value sets the horizontal offset of the shadow.
The second value sets the vertical offset of the shadow.
The third value sets the blur radius of the shadow.
The fourth value sets the color of the shadow.
none
Specifies that no shadow is to be on the container
<style type="text/css">
#myDiv
{
background: #666;
border: #999 1px solid;
height: 90px;
margin-bottom: 12px;
padding: 10px;
color: #FFF;
box-shadow: inset 3px 3px 3px #000, 1px 1px 3px #FFF;
}
#container
{
background: #C0C0C0;
padding: 20px;
}
</style>
<div id="container">
<div id="myDiv">
Sonia ...Sonia ...Sonia ...Sonia ...Sonia ...Sonia ...Sonia ...Sonia ...Sonia ...Sonia
...Sonia ...Sonia ...Sonia ...Sonia ...</div>
</div>
CSS ceneterd-image Property example
<html>
<head>
<title>Css</title>
<style type="text/css">
body
{
background-image: url(4113.jpg);
background-position: center top;
background-repeat: no-repeat;
background-attachment: scroll;
background-color: #FFFFFF;
}
</style>
</head>
<body>
<h1>
sonia</h1>
</body>
</html>
CSS direction-property example
The CSS direction property is used to specify the writing direction in an element. It also affects the direction of a table column layout, as well as the horizontal content overflow direction of an element.
<style type="text/css">
#div1
{
direction: ltr;
}
#div2
{
direction: rtl;
}
#div1, #div2
{
width: 240px;
background: #FEEAAB;
padding: 12px;
margin: 12px;
}
</style>
<div id="div1">
My DIV content.</div>
<div id="div2">
My DIV content.</div>
CSS empty-cells-hide Property example
The CSS empty-cells property is used to specify whether or not tables should render empty cells.
<!DOCTYPE html>
<style type="text/css">
#myTable
{
empty-cells: hide;
border: #F0F 3px double;
background: #FFDDFC;
}
#myTable td
{
border: #000 1px solid;
background: #CCC;
}
</style>
<table id="myTable">
<tr>
<td>
sonia
</td>
<td>
sonia
</td>
<td>
</td>
</tr>
<tr>
<td>
sonia
</td>
<td>
</td>
<td>
sonia
</td>
</tr>
</table>
CSS empty-cells-show Property example
<!DOCTYPE html>
<style type="text/css">
#myTable
{
empty-cells: show;
border: #F0F 3px double;
background: #FFDDFC;
}
#myTable td
{
border: #000 1px solid;
background: #CCC;
}
</style>
<table id="myTable">
<tr>
<td>
sonia
</td>
<td>
sonia
</td>
<td>
</td>
</tr>
<tr>
<td>
sonia
</td>
<td>
</td>
<td>
sonia
</td>
</tr>
</table>
CSS visibility Property example
The CSS visibility property is used to hide content while maintaining the real estate it would occupy in the document layout. It will make the element disappear but its real estate remains.
To let other page elements occupy the real estate where invisible content resides, use the display property with a value of "none" instead of the visibility property set to "hidden".
Possible Values:
hidden
Hide the element.
<style type="text/css">
.divClass
{
background: #C6E2FF;
border: #09F 1px solid;
height: 30px;
}
#div2
{
visibility: hidden;
}
</style>
<div id="div1" class="divClass">
div content ...</div>
<div id="div2" class="divClass">
div content ...</div>
<div id="div3" class="divClass">
div content ...</div>
visible
Show the element.
<style type="text/css">
.divClass
{
background: #C6E2FF;
border: #09F 1px solid;
height: 30px;
}
#div2
{
visibility: visible;
}
</style>
<div id="div1" class="divClass">
div content ...</div>
<div id="div2" class="divClass">
div content ...</div>
<div id="div3" class="divClass">
div content ...</div>
CSS horizontal-image-repetititon Property example
<html>
<head>
<title></title>
<style>
body
{
background-image: url(4113.jpg);
background-repeat: repeat-x;
background-attachment: scroll;
}
</style>
</head>
<body>
sonia
</body>
</html>
CSS left Property example
The CSS left property is used to offset an element's left position. It moves the element to the right and the position property of the element determines the behavior of the placement it gets.
<style type="text/css">
.divClass
{
background: #AFF;
border: #0BB 1px solid;
width: 200px;
position: relative;
}
#myDiv
{
left: 100px;
}
</style>
<div class="divClass">
my 1st div</div>
<div class="divClass" id="myDiv">
my 2nd div</div>
<div class="divClass">
my 3rd div</div>
CSS max-height Property example
The CSS max-height property is used to set the maximum height that an element can grow to be. Use with min-height to create a height range for the element. Use in conjuction with the overflow property to show scrollbars or hide content that might go beyond the max-height of the element.
The example below creates a height range in which the element cannot be less than 90px high, and cannot be more than 200px high.
<!DOCTYPE html>
<style type="text/css">
#myDiv
{
max-height: 200px;
min-height: 90px;
background: #FFCAFF;
overflow: auto;
}
</style>
<div id="myDiv">
<p>
paragraph content ...</p>
<p>
paragraph content ...</p>
<p>
paragraph content ...</p>
<p>
paragraph content ...</p>
<p>
paragraph content ...</p>
<p>
paragraph content ...</p>
<p>
paragraph content ...</p>
<p>
paragraph content ...</p>
<p>
paragraph content ...</p>
</div>
CSS max-width Property example
The CSS max-width property is used to specify the maximum width an element can grow to be. Use with min-width to create a width range for the element.
The example below creates a width range in which the element cannot be less than 300px wide, and cannot be more than 400px wide. To see the effect run this code in a new HTML document, and slowly resize your browser window horizontally making it smaller.
<!DOCTYPE html>
<style type="text/css">
#myDiv
{
max-width: 400px;
min-width: 300px;
background: #FFCAFF;
height: 120px;
}
</style>
<div id="myDiv">
Div content ...</div>
CSS min-height Property example
The CSS min-height property is used to specify the minumum height an element should be. Use with max-height to create a height range for the element.
<!DOCTYPE html>
<style type="text/css">
#myDiv
{
min-height: 90px;
max-height: 200px;
background: #FFCAFF;
}
</style>
<div id="myDiv">
<p>
paragraph content ...</p>
</div>
CSS min-width Property example
The CSS min-width property is used to specify the minimum width an element should be. Use with max-width to create a width range for the element.
The example below creates a width range in which the element cannot be less than 300px wide, and cannot be more than 400px wide. To see the effect run this code in a new document, and resize your browser window horizontally.
<!DOCTYPE html>
<style type="text/css">
#myDiv
{
min-width: 300px;
max-width: 400px;
background: #FFCAFF;
height: 120px;
}
</style>
<div id="myDiv">
Div content ...</div>
CSS outline-color Property example
The CSS outline-color property is used to specify the color of an outline. Outlines are somewhat similar to borders, however outlines are drawn on the outside of elements and do not affect the position or size of the element.
<!DOCTYPE>
<style type="text/css">
.class1
{
outline-color: #09F;
outline-width: 7px;
outline-style: inset;
border-color: #F00;
border-width: 7px;
border-style: inset;
padding: 5px;
}
</style>
<p class="class1">
my content ...</p>
<p class="class1">
my content ...</p>
CSS outline-style Property example
The CSS outline-style property is used to specify the style of an outline. Outlines are somewhat similar to borders, however outlines are drawn on the outside of elements and do not affect the position or size of the element.
<!DOCTYPE>
<style type="text/css">
.class1
{
outline-color: #09F;
outline-width: 7px;
outline-style: inset;
border-color: #F00;
border-width: 7px;
border-style: inset;
padding: 5px;
}
</style>
<p class="class1">
my content ...</p>
<p class="class1">
my content ...</p>
CSS outline-width Property example
The CSS outline-width property is used to specify the width of an outline drawn onto an element. Outlines are somewhat similar to borders, however outlines are drawn on the outside of elements and do not affect the position or size of the element.
<!DOCTYPE>
<style type="text/css">
.class1
{
outline-color: #09F;
outline-width: 7px;
outline-style: inset;
border-color: #F00;
border-width: 7px;
border-style: inset;
padding: 5px;
}
</style>
<p class="class1">
my content ...</p>
<p class="class1">
my content ...</p>
CSS outline Property example
The CSS outline property is shorthand for specifying the outline-color, outline-style and outline-width properties.
<!DOCTYPE>
<style type="text/css">
.class1
{
outline: #09F inset 7px;
border: #F00 inset 7px;
padding: 5px;
}
</style>
<p class="class1">
my content ...</p>
<p class="class1">
my content ...</p>
CSS overflow-x Property example
The CSS overflow-x property is used to specify how content inside of an element should be clipped along the X axis, which is the horizontal plane. If you set the width of an element, and the width of the content inside of that element happens to exceed the width of its parent, use overflow-x to handle how the overflowing content is treated.
Possible Values:
auto
This setting will make a scroll bar appear only if the content requires it.
scroll
This setting will make a scroll bar appear.
visible
This setting will make no scroll bar and will not hide the overflow content.
hidden
This setting will make no scroll bar and it will hide the overflow content.
<style type="text/css">
div#myDiv
{
width: 120px;
overflow-x: auto;
height: 50px;
padding: 10px;
}
</style>
<div id="myDiv">
ABCDEFGHIJKLMNOPQRSTUVWXYZ</div>
CSS overflow-y Property example
The CSS overflow-y property is used to specify how content inside of an element should be clipped along the Y axis, which is the vertical plane. If you set the height of an element, and the height of the content inside of that element happens to exceed the height of its parent, use overflow-y to handle how the overflowing content is treated.
Possible Values:
auto
This setting will make a scroll bar appear only if the content requires it.
scroll
This setting will make a scroll bar appear.
visible
This setting will make no scroll bar and will not hide the overflow content.
hidden
This setting will make no scroll bar and will hide the overflow content.
<style type="text/css">
div#myDiv
{
height: 80px;
overflow-y: auto;
}
</style>
<div id="myDiv">
ABCDEFGHIJKLMNOPQRSTUVWXYZ
<hr />
ABCDEFGHIJKLMNOPQRSTUVWXYZ
<hr />
ABCDEFGHIJKLMNOPQRSTUVWXYZ
<hr />
ABCDEFGHIJKLMNOPQRSTUVWXYZ
</div>
CSS quotes Property example
The CSS quotes property is used to specify the characters that will encapsulate a string of quoted text.
<!DOCTYPE html>
<style type="text/css">
#p1 > q
{
quotes: "'" "'";
}
#p2 > q
{
quotes: '"' '"';
}
#p3 > q
{
quotes: "[" "]";
}
</style>
<p id="p1">
<q>A</q></p>
<p id="p2">
<q>A</q></p>
<p id="p3">
<q>A</q></p>
CSS relative-position Property example
relative
Allows the offset properties to apply to the element and its positioning is relative to its parent container and sibling elements.
<style type="text/css">
#container
{
border: #999 1px dashed;
height: 100px;
}
#container div
{
position: relative;
background: #FFD5FF;
border: #F0F 1px solid;
padding: 10px;
width: 20px;
height: 20px;
}
#div1
{
top: 20px;
left: 20px;
}
#div2
{
top: 40px;
left: 40px;
}
#div3
{
top: 60px;
left: 60px;
}
</style>
<div id="container">
<div id="div1">
A</div>
<div id="div2">
B</div>
<div id="div3">
C</div>
</div>
CSS right Property example
The CSS right property is used to offset an element's right position. It moves the element to the left and the position property of the element determines the behavior of the placement it gets.
<style type="text/css">
.divClass
{
background: #FFEDC4;
border: #FDB100 1px solid;
width: 300px;
padding: 8px;
float: right;
position: relative;
clear: right;
}
#myDiv
{
right: 150px;
}
</style>
<div class="divClass">
my 1st div</div>
<div class="divClass" id="myDiv">
my 2nd div</div>
<div class="divClass">
my 3rd div</div>
CSS text-shadow Property example
The CSS text-shadow property is used to render shadows for text. Each distinct shadow gets 2 - 4 values and an optional "inset" keyword.
You can create a comma-separated list of distinct shadows that will apply under the same text to create various looking effects.
Possible Values:
specify shadow settings
Example: "inset 1px 2px 3px #000"
The optional inset keyword makes the shadow inset as opposed to rendering it under the text.
The first value sets the horizontal offset of the shadow.
The second value sets the vertical offset of the shadow.
The third value sets the blur radius of the shadow.
The fourth value sets the color of the shadow.
<style type="text/css">
#myDiv
{
background: #EBB7FF;
padding: 10px;
font-family: "Arial Black" , Gadget, Arial, serif;
font-size: 18px;
color: #D634FE;
text-shadow: 1px 2px 1px #000, 2px 4px 4px #999;
}
</style>
<div id="myDiv">
<h2>
Welcome to My Website</h2>
<p>
Blah blah blah blah blah and more blah ...</p>
</div>
CSS repaeting-tiles Property example
<html>
<head>
<title>CSS</title>
<style type="text/css">
body
{
background-image: url(4113.jpg);
}
</style>
</head>
<body>
sonia
</body>
</html>
CSS top Property example
The CSS top property is used to offset an element's top position. It moves the element downward and the position property of the element determines the behavior of the placement it gets.
<style type="text/css">
span.allSpans
{
background: #FFD7FF;
border: #F0F 1px solid;
}
#mySpan
{
top: 10px;
position: relative;
}
</style>
<span class="allSpans">my span content</span> <span class="allSpans" id="mySpan">my
span content</span> <span class="allSpans">my span content</span>
CSS Background Image Strip that repeats vertically
<html>
<head>
<title>CSS</title>
<style type="text/css">
body
{
background-image: url(4113.jpg);
background-position: center;
background-repeat: repeat-y;
background-attachment: scroll;
}
</style>
</head>
<body>
sonia
</body>
</html>
CSS z-index Property example
The CSS z-index property is used to layer elements by specifying their z-axis hierarchy number in the stack order of elements. Higher indexes stack on top of lower indexes.
The effect is only seen on containers that are positioned in such a way that they overlap or cover one another.
<style type="text/css">
#container
{
border: #999 1px dashed;
height: 100px;
}
#container div
{
position: absolute;
background: #FFD5FF;
border: #F0F 1px solid;
padding: 10px;
text-align: center;
width: 20px;
height: 20px;
}
#div1
{
z-index: 3;
top: 20px;
left: 20px;
}
#div2
{
z-index: 2;
top: 40px;
left: 40px;
}
#div3
{
z-index: 1;
top: 60px;
left: 60px;
}
</style>
<div id="container">
<div id="div1">
A</div>
<div id="div2">
B</div>
<div id="div3">
C</div>
</div>
Summary
Through this article you are able to design web pages.