×

CSS Position

CSS Position: The position property in CSS is applied to set the position of the elements. It can be used to position the backside of an element. It is also helpful for the scripted animation outcome.

We can place an element with the use of the left, right, top, and bottom properties. Firstly, we have to set the position property before using these properties. A computed position of the position element can be absolute, relative, sticky, and fixed.

There are some Positioning in CSS, which are listed below:

  • Static Positioning in CSS
  • Fixed Positioning in CSS
  • Relative Positioning in CSS
  • Absolute Positioning in CSS

Static Positioning in CSS

The static position is used as the default position on the web. It sets the element’s position always on the basis of the general flow of a page. This property can’t be affected by any left, right, top, and bottom properties.

Fixed Positioning in CSS

A fixed text over the browser can be used efficiently by the use of this fixed poisoning CSS property. The text will not move even when we scroll that window.

Example:

Consider the following example:

<!DOCTYPE html>
<html>
<head>
<style>
p.pos_fixed
{
 position: fixed;
 top: 50px;
 right: 10px;
 color: green;
}
</style>
</head>
<body>
<p> Ant text...</p>
<p> Ant text...</p>
<p> Ant text...</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> ........</p>
<p> Ant text...</p>
<p> Ant text...</p>
<p> Ant text...</p>
<p class= "pos_fixed"> Scroll the page. This text is not moving. </p>
</body>
</html>

Output:

Relative Positioning in CSS

This property in CSS sets an element that is relative to their normal position.

Example:

Consider the following example:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
h2.pos_left
{ 
 position: relative; 
 left: -10px; 
} 
h2.pos_right
{ 
 position: relative; 
 left: 30px; 
} 
</style> 
</head> 
<body> 
<h2>There is no position specified in this heading. </h2> 
<h2 class="pos_left"> This is a left positioned heading on the basis of its general position </h2> 
<h2 class="pos_right"> This is a left positioned heading on the basis of its general position </h2> 
<p>This style "left:-10px" subtracting 10 pixels from an element's real left position.</p> 
<p>This style "left:30px" adding 30 pixels to an element's real left position.</p> 
</body> 
</html> 

 Output:

Absolute Positioning in CSS

The absolute positioning in CSS is employed to position any component, i.e., relative to its first parent component that includes any position other than the static position. If no such component is found, the corresponding block is HTML. We can place the component anywhere on the page by using this absolute positioning.

Example:

Take a look on the following example:

<!DOCTYPE html> 
<html> 
<head> 
<style> 
h2
{ 
 position: absolute; 
 left: 160px; 
 top: 260px; 
} 
</style> 
</head> 
<body> 
<h2> This heading is specified with the absolute position </h2>
<p> This paragraph is positioned 160 pixels from the left side and 260 pixels from the top of this page. </p>
</body>
</html> 

 Output:

← Prev Next →


Related Topics

CSS Superscript and Subscript

Superscript and Subscript To specify the superscript and the subscript text, HTML provides us two tags that are <sup> and <sub>. The superscript content looks in the shorter font and half...

2 minutes read.

CSS White Space Property

White Space in CSS The white-space CSS property describes how to show the content inside an element. This property is applied to manage a white space within an element. Values of White-space...

2 minutes read.

How to create blinking text using CSS

The blinking effect is used in HTML and CSS to take the attraction towards a particular word or section. If you need such a blinking effect, we need to take...

2 minutes read.

CSS Pseudo-elements

Pseudo-elements The pseudo-classes in CSS can be represented as any keyword which is connected to the selector that represents any selected element’s unique state. On the other hand, pseudo-elements can be...

6 minutes read.

CSS Font-Size

A Cascading Style Sheet (CSS) is a simple design scripting language intended to simplify the process of making web pages more visually appealing with the kind of high-level formatting. Cascading...

3 minutes read.

What is Bootstrap CSS?

Bootstrap: - Bootstrap is a CSS framework that is free to use and is used for the front-end development of the website in a faster and easier way. Bootstrap was released as...

3 minutes read.

CSS Text-Overflow

Introduction: The text-overflow property of CSS is used to format the text which is overflowing the boundaries of the container. This property helps user to clip the text, to display the...

5 minutes read.

CSS Arrow

CSS Arrow The arrow of CSS is applied to insert an array with the tooltip. It can make a tooltip as any speech bubble. Also, this arrow can be illustrated in...

4 minutes read.

How to center a table in CSS

The table is used to store and arrange the data in tabular format. The data here can be of any form like text, image, links, etc. The table is made...

3 minutes read.

CSS Variables

CSS Variables These variables of CSS are applied to add the custom property values to our various web-pages. The custom properties are often called as CSS variables or cascading variables. Various...

4 minutes read.

How to Set Space between the Flexbox

For managing layout on the Web, CSS Flexbox and CSS Grid are two excellent tools. Flexbox handles one-dimensional layouts quite well, whereas CSS Grid manages two-dimensional layouts with columns and...

4 minutes read.

CSS Table

CSS table provides better look and feel. There are various properties of CSS table that are given below. border border-collapse padding width height text-align color background-color CSS Table Border You can set...

4 minutes read.

CSS Functions

CSS functions are used for different CSS properties. Every front-end developer should have knowledge of all CSS functions. It makes the coding easier. FunctionsExplanationattr().It returns the value of an attribute of...

5 minutes read.

CSS Width

CSS Width The width property in CSS sets the content width of area of the element. These properties do not provide margin and border features. It is used to set the...

1 minute read.

How to edit CSS in WordPress

Developing a new website or blog is a difficult undertaking. We want to create something that the consumers will adore, but we might not want the setting to take months and...

7 minutes read.

CSS Counters

CSS Counters: The CSS counter property is similar to the variables. CSS counters are controlled via CSS, and its values are incremented via rules of CSS to record how much...

4 minutes read.

CSS Ellipsis

The CSS ellipsis kind of is the value that mostly is used by the property: text-overflow. Here, we will discuss the following: What is CSS Ellipsis? Syntax for CSS ellipsis How to...

3 minutes read.

CSS Word Wrap

Word Wrap in CSS: The word-wrap property in CSS is referred to break any lengthy word and wrap towards the next or following line. It is employed for preventing overflow...

1 minute read.

Is CSS a programming language?

 A programming language is a set of grammatical rules and a vocabulary for commanding a machine to accomplish specified tasks. High-level languages like BASIC, C, C++, COBOL, Java, FORTRAN, Ada...

4 minutes read.

CSS Masking

CSS Masking The CSS mask property is applied to hide a component with the use of the masking or clipping an image at any specific point. The masking depicts the use...

3 minutes read.