By default, a browser renders the webpage, by placing elements on the webpage from left-to-right and from top-to-bottom. The style rule position can be used to override this default behavior. When you specify an element's "position:absolute" you can use the "left" and "top" properties to take an element out of the normal flow and place it exactly where you want it on the webpage.
Welcome to Bucaro TecHelp!

Welcome to Bucaro TecHelp!
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact Advertise on Bucaro TecHelp Advertise Here RSS News Feeds News Feeds

HTML5 Solutions: Essential Techniques for HTML5 Developers

Essential Techniques for HTML5 Developers

HTML5 brings the biggest changes to HTML in years. Web designers now have new techniques, from displaying video and audio natively in HTML, to creating realtime graphics on a web page without a plugin.

This book provides a collection of solutions to all of the most common HTML5 problems. Every solution contains sample code that is production-ready and can be applied to any project.

Click Here

position:absolute

Default Positioning

One of the most important CSS webpage layout concepts to understand is how to position webpage elements. Every element on a webpage, be it an image, a drop-down list, or just a paragraph of text, is actually a rectangular box, referred to as an element. When a Web browser loads an html file, it parses the html code from left-to-right top-to-bottom, just as we would read it and, by default, it renders the webpage, by placing elements on the webpage from left-to-right and from top-to-bottom. You can think of this as the webpage elements as "flowing" into position. As the elements flow onto the webpage, they line themselves up along a "baseline".

Webpage elements that flow into position from left-to-right are called inline elements. If there isn't enough room to the right to place an element, the browser places it on the next line. Certain elements, like paragraphs <p>, divisions <div>, and horizontal rules <hr />, called block elements, do not normally flow on the webpage from left-to-right. Block elements, by default, start on a new line, causes the next element in the flow to start a new line.

The style rule position is used to override this default behavior. The value of the position element may be set to relative, absolute, or fixed. In this article, I'll describe the effect of setting the style rule position: relative.

Shown below is the code for a webpage containing three span elements and how they would be rendered by default in the browser.

<html>
<head>

<style type="text/css">
.myBox
{
background-color:crimson;
border-style:solid;
border-width:1px;
padding:4px;
}
</style>

</head>
<body>

<span class="myBox">Element 1</span>
<span class="myBox">Element 2</span>
<span class="myBox">Element 3</span>

</body>
</html>

Normal inline flow

Absolute Positioning

When you specify an element's position:absolute you can relocate the element to the exact position where you want it to go. You can use the left and ⁄ or top property to place the element exactly where you want on the webpage.

<html>
<head>

<style type="text/css">
.myBox
{
background-color:crimson;
border-style:solid;
border-width:1px;
padding:4px;
width:80px;
}
#myAbs
{
position:absolute;
left:40px;
top:30px;
background-color:crimson;
border-style:solid;
border-width:1px;
padding:4px;
width:80px;
}
</style>

</head>
<body>

<span class="myBox">Element 1</span>
<span id="myAbs">Element 2</span>
<span class="myBox">Element 3</span>

</body>
</html>

Absolute Positioning

Note that Element 2 is absolute positioned 40 pixels to the right and 30 pixels down from the upper-left corner of its containing element (the <body> element).

Note that the values of left and top are offsets relative to the element's containing element NOT offsets with respect to another element. Other elements, even other absolute positioned elements are not affected by the offsets, so the absolute positioned element could overlap other elements.

RSS Feed RSS Feed



Web Design Sections

HTML5 and CSS3 Quick Reference

This book is an essential technical dictionary for professional web designers and developers, conveniently summarizing over 3000 pages of (X)HTML5 and CSS3 specifications and covering the most common and fundamental concepts and specs, including tags, attributes, values, objects, properties, methods, events, and APIs.

Web Designer Manu Gautrand says,"It's easy to find what you are looking for and most tags⁄properties have good code examples and specify in what browser versions the tag is supported. Click here for more information.


Best Laptop Deals at TigerDirect
[Site User Agreement] [Advertise on This site] [Search This Site] [Contact Form]
Copyright©2001-2011 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268