When a user srolls the browser window, the contents of the window move in the oposite direction of the scroll bar. The style rule position can be used to override this default behavior. When you specify an element's "position:fixed" it won't move when the user scrolls the window.
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:fixed

Default Behavior

When a user srolls the browser window, the contents of the window move in the oposite direction of the scroll bar. Shown below is the code for a webpage containing six div elements and how they would be positioned after the user scrolled the browser window.

<html>
<head>

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

</head>
<body>

<div class="myBox">Element 1</div>
<div class="myBox">Element 2</div>
<div class="myBox">Element 3</div>
<div class="myBox">Element 4</div>
<div class="myBox">Element 5</div>
<div class="myBox">Element 6</div>

</body>
</html>

Scrolled Browser Window

Fixed Positioning

When you specify an element's position:fixed, you take the element out of the normal flow, and cause it to remain fixed in positioned when the browser window is scrolled. Shown below is the code for a webpage containing six div elements, with one of the div elements position:fixed specified, and how they would be positioned after the user scrolled the browser window.

<html>
<head>

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

</head>
<body>

<div class="myBox">Element 1</div>
<div class="fixedBox">Element 2</div>
<div class="myBox">Element 3</div>
<div class="myBox">Element 4</div>
<div class="myBox">Element 5</div>
<div class="myBox">Element 6</div>

</body>
</html>

Element 2's position fixed

You can use the left and ⁄ or top property to place the element exactly where you want in the browser window, and it will remain at that position regardless of scrolling.

• Note: IE6 and lower do not support fixed positioning, IE7 with "Strict" DOCTYPE does support fixed positioning.

Content is Currency

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