Quantcast
Channel: CSS Atoms | CSS3 tutorials, tips, and articles » Basic
Viewing all articles
Browse latest Browse all 10

All You Want to Know About CSS Static Positioning

$
0
0

CSS Position Property is the method that web designers use when they want to place any element on their page. This property has four different types of positioning: Absolute, Fixed, Relative, and Static. In this tutorial we are going to learn all about Static Positioning. All the elements by default are Static Positioned. When an element is static, it ignores any placement declarations. By default, Static Positioning place elements relative to the sides of the page.

The other three types of positioning will be explained on other tutorials.

NOTE: This tutorial was completed using XHTML 1.0 Transitional with CSS. It is assumed you have basic knowledge of HTML and CSS principles.

We moved our web sites to Server Intellect and have found them to be incredibly professional. Their setup is very easy and we were up and running in no time.

STEP ONE:
I created a XHTML document with different <div>s tags: One for the header, one for a container that includes a <div> for the content, and one for the footer.

Let’s have a look at the initial HTML setup:

Code Block
index.html
New <div id> for our image
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Relative Positioning</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div class="header">
<!-- end .header --></div>

<div class="container">

<div class="content">

<!-- end .content --></div>

<!-- end .container --></div>

<div class="footer">
<!-- end .footer --></div>

</body>

</html>
Also, I added a Cascading Styling Sheet to it. Download the source files to obtain the entire code for this tutorial.

STEP TWO:
Let’s add an image into our content <div>. Wait! We don’t want our image to be part of the content. Easy! Let’s create a <div> for it.

Code Block
Default.aspx
Code Block Description
<div class="content">
   
    <div id="CheckMark">
    <img src="images/CheckMark.gif" width="39" height="36" alt="Check Mark" />
<!-- end #CheckMark --></div>

    <!-- end .content --></div>
Why a <div>?  A <div > outlines a separation in an HTML page. It also makes the process of styling elements with CSS easier.

STEP THREE:
Notice that our image was directly positioned at the left side of our page (traditional layout).
We don’t need a CSS rule to specify Static Positioning. If we add top, bottom, left, right declarations, they will be ignored.

STEP FOUR:
Debug in your favorite browser the HTML page. You’ll see your image is right where we put it. If we don’t change its position to Absolute, Fixed, or Relative, the element is not going to move. Therefore, it will be always positioned according to the layout of the page.

STEP FIVE:
To conclude, let’s learn some facts about Static Positioning:

  • There is no need to declare Static Positioning.
  • Static Positioning is the default behavior for any element.
  • Unless you apply an Absolute, Fixed, or Relative declaration, elements will appear in the order they occur in the HTML markup.
  • It avoids top, bottom, left, right placement declarations.

That’s all! You learned how Static Positioning is initially declared.

I just signed up at Server Intellect and couldn’t be more pleased with my fully scalable & redundant cloud hosting! Check it out and see for yourself.

Download Static Positioning File


Viewing all articles
Browse latest Browse all 10

Trending Articles