CSS Position properties

CSS position propertiesCSS position property is generally used to overlap the elements. By setting direction (left, right, top, bottom), you can set the position of an element. An element can be overlapped by using position properties. Directions will not work until you specify position property.

This article will teach you.

  • CSS position property with explanation and examples.
  • Making an awesome book cover page using CSS position properties.

There are following kind of CSS position properties.

  • Static.
  • Fixed.
  • Absolute
  • Relative.

Static.

By default, CSS position properties set to static. You can’t set direction for static position property.

Fixed.

The element affected by fixed position will hold its position even if the page is being scrolled. The element will overlap. In short, Fixed position is similar to absolute position, but the element will hold its position even if the page is being scrolled.

<head>
<style>
h2 {
position: fixed;
left: 100px;
color:red;
top:80px;
}
</style>
</head>

<body><h2>SEOWEBSITEBLOG.COM</h2>
CSS-position example</br> CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br></body>

 

Absolute.

The element affected by absolute position will lose its space. Other elements will behavior like the element affected by absolute position is not there. The absolute positioned element can overlap other elements.

<head>
<style>
h2 {
position: relative;
left: 100px;
color:red;
top:80px;
}
</style>
</head>

<body><h2>SEOWEBSITEBLOG.COM</h2>
CSS-position example</br> CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br></body>

 

Relative.

The element affected by the relative position property will not lose its space. Elements can be moved by setting direction. If an element moves down or top, then you will see an empty space to its original position.

<head>
<style>
h2 {
position: absolute;
left: 100px;
color:red;
top:80px;
}
</style>
</head>

<body><h2>SEOWEBSITEBLOG.COM</h2>
CSS-position example</br> CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br>CSS-position example</br></body>

Now it’s time to do one fantastic practical.

<head>
<style>

div#background
{
height:450px;
width: 350px;
background-color: #CCFF66;
}

div#verticalbox
{
height:450px;
width: 100px;
background-color: #0066FF;
position:absolute;
left:200px;
}

div#horizontalbox
{
height:75px;
width: 350px;
background-color:#00CC66;
color:white;
position:absolute;
top:60px;
}

p
{
position:absolute;
top:375px;
font-size:20px;
}

img
{
height:200px;
width:350px;
position:absolute;
top:150px;
}

</style>
</head>

<body>
<div id=”background”>
<div id=”verticalbox”></div>
<div id=”horizontalbox”><center><h1>CSS tutorial</h1></center></div>
<p>by Sushrut zemse</p>
<img src=”http://seowebsiteblog.com/wp-content/uploads/2015/02/CSS-HTML.png”>
</div>
</body>

CSS positionproperty practical-CSS book

Comments

comments