Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

position in CSS

Tags:

css

what is difference between relative position and absolute position is CSS eg .style { position:relative; }

.style { position:absolute; }

like image 885
Piyush Avatar asked May 31 '10 08:05

Piyush


People also ask

Is it good to use position in CSS?

If you want to make stunning websites that looks artistic, unique, and beautiful, then you should definitely learn how to use the CSS position property. Let's see how it works. But, using the position property, you can place your content anywhere you wish by detaching each element from the other elements.

What is object position in CSS?

The object-position CSS property specifies the alignment of the selected replaced element's contents within the element's box. Areas of the box which aren't covered by the replaced element's object will show the element's background.

What is the difference between position and display in CSS?

Position property determines in what manner an item is positioned on the page or relative to one another. CSS's Display property specifies the type of rendering box that is created from our HTML you can say it like block, inline, inline block, flex.


4 Answers

From W3schools:

Absolute

Generates an absolutely positioned element, positioned relative to the first parent element that has a position other than static. The element's position is specified with the "left", "top", "right", and "bottom" properties

Relative

Generates a relatively positioned element, positioned relative to its normal position, so "left:20" adds 20 pixels to the element's LEFT position

Also check this page, it will give you very nice overview about positions in CSS.

like image 99
Ondrej Slinták Avatar answered Oct 20 '22 13:10

Ondrej Slinták


The standard describes it here: Comparison of normal flow, floats, and absolute positioning

Is there something in particular about this which you don't understand or want explaining further?

like image 35
ChrisW Avatar answered Oct 20 '22 12:10

ChrisW


With relative you can position the element relative to its original position and the original space is still holding the item.

Absolute takes the item out of the regular flow of the HTML and you can position it relative to the parent element.

like image 42
red-X Avatar answered Oct 20 '22 13:10

red-X


Here is a good tutorial about that:

http://jimbojw.com/wiki/index.php?title=Position_absolute_is_really_relative%3F

like image 25
Sarfraz Avatar answered Oct 20 '22 12:10

Sarfraz