<

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

CSS Positioning - Relative vs Absolute vs Fixed

Posted on
6,276 Points
276 Views
Last Modified:
Experience Level: Beginner
5:09
In this tutorial viewers will learn how to position items using CSS's three positioning types

Video Steps

1. Create a new HTML document with an internal stylesheet.

2. Create another div in CSS and name it Absolute

3. Type "position:absolute;" and "top:10px; left:50px;". Define its background-color as blue. Define its dimensions as 500 by 500px.

4. Create a div in CSS and name it Relative

5. Type "position:relative;" and "top:10px; left -30px;". Define its background-color as red. Define its dimensions as 300 by 300px. Relatively positioned elements are positioned relative to its normal position; that is, if it would ordinarily be at position left:50px because of its container div, typing left:-20px would send it back to the 30px position.

6. Create another div in CSS and name it Fixed

7. Type "position:fixed;" and "top:10px; left:10px;". Define its background-color as yellow. Define its dimensions as 50 by 50px. Create another div for a Container and define its height as 1000px. Fixed elements do not move, even when the page is scrolled.

8. In HTML, type the tags for all of the divs. Place the Relative div inside the Absolute div. Place all the divs inside the Container div. Refresh the page to see the effects.

0
Comment
0 Comments

Featured Post

PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Join & Write a Comment

Suggested Videos

Title Views Activity
Embedded Flash in HTML5 102
Introduction to HTML (Part 1) 111
Introduction to HTML (Part 2) 149
Introduction to PHP: Building the Form 427
This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month