×

Tailwind CSS Position

The position class acknowledges more than one value in tailwind CSS. It is an option in contrast to the CSS Position property. This class is utilized for controlling how an element is situated in the DOM.

Position classes

The various position classes in Tailwind CSS are classified as:

  • Static
  • Fixed
  • Absolute
  • Relative
  • sticky

static class

This class is utilized to set the place/position of an element as indicated by the ordinary flow of the document.

Syntax

<element class="static">...</element>

Example:

<!DOCTYPE html>
<head>
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
rel="stylesheet">
</head>
<body class="text-center">
<center>
<h1 class="text-red-600 text-5xl font-bold">
Tutorial and Example
</h1>
<b>Position Class - Tailwind CSS </b>
<div class="static text-left p-2 m-2 bg-orange-200 h-48"> 
<p class="font-bold">Static Parent</p>
<div class="absolute bottom-0 left-0 p-2
bg-red-500">
<p>Absolute Child</p>
</div>
</div>
</center>
</body>
</html>

Output:

Tailwind CSS Position

fixed class

This class will be situated fixed to the viewport. An element with fixed situating permits it to stay at a similar position even we scroll the page. We can set the place/position of the element utilizing the top, right, bottom, left.

Syntax:

<element class="fixed">...</element>

Example:

<!DOCTYPE html>
<head>
<link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
rel="stylesheet">
</head>


<body class="text-center">
<center>
<h1 class="text-red-600 text-5xl font-bold">
Tutorial and Example
</h1>
<b>Position Class - Tailwind CSS </b>
<div class="overflow-auto bg-red-200
mx-16 h-24 text-justify">
<div class="float-right fixed">
<p class="bg-red-500 p-2">
Tutorial and Example Fixed Child
</p>


</div>


<p>
How frequently were you baffled while
paying special attention to a decent assortment of
programming/calculation/inquiries questions?
What did you expect and what did you get?
This entrance has been made to give
elegantly composed, very much idea and 
well-clarified answers for chosen questions.
An IIT Roorkee former student and organizer of
Javatpoint. He loves to settle programming
Issues in most proficient ways. Aside from
Javatpoint, has worked with DE Shaw
, what's more, Co. as a product engineer and JIIT
Noida as an associate teacher. It is a
great stage to get the hang of programming. It is
an instructive site. Get ready for the
Enrolments drive of item-based organizations
like Microsoft, Amazon, Adobe, and so on with a
free web-based position arrangement course.
</p>


</div>
</center>
</body>


</html>

Output:

Tailwind CSS Position

In that above output, if we scroll the scrollbar up-down the content will scroll and the “Javatpoint Fixed Child” remain constant.

absolute class

This class is utilized to set the place/position of an element outside the normal flow of the document, making adjoining elements go about as though the element doesn't exist.

Syntax:

<element class="absolute">...</element>

Example:

<!DOCTYPE html>
<head>
<link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
rel="stylesheet">
</head>


<body class="text-center">
<center>
<h1 class="text-red-600 text-5xl font-bold">
Tutorial and Example
</h1>
<b>Position Class - Tailwind CSS </b>
<div class="static text-left p-2 m-2 bg-red-200 h-48"> 
<p class="font-bold">Static parent</p>




<div class="absolute bottom-0 left-0 p-2
bg-red-500">


<p>Absolute child</p>


</div>
</div>
</center>
</body>
</html>

Output:

Tailwind CSS Position

relative class

This class is utilized to set the place/position of an element comparative with the ordinary/normal flow of the document.

Syntax:

<element class="relative">...</element>

Example:

<!DOCTYPE html>
<head>
<link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
rel="stylesheet">
</head>


<body class="text-center">
<center>
<h1 class="text-red-600 text-5xl font-bold">
Tutorial and Example
</h1>
<b>Position Class - Tailwind CSS </b>
<div class="static text-left p-2 m-2 bg-red-200 h-48"> 
<p class="font-bold">Static parent</p>




<div class="relative p-2 inline-block
bg-red-500">


<p>Relative child</p>


</div>
<div class="relative p-2 inline-block
bg-red-600">


<p>Relative Sibling child</p>


</div>
</div>
</center>
</body>
</html>

Output:

Tailwind CSS Position

sticky class

This class is utilized to set the place/position of an element as relative until it passes a specific threshold, then, at that point, it regards it as fixed until its parent is off-screen.

Syntax

<element class="sticky">...</element>

Example:

<!DOCTYPE html>
<head>
<link href=
"https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"
rel="stylesheet">
</head>


<body class="text-center">
<center>
<h1 class="text-red-600 text-5xl font-bold">
Tutorial and Example
</h1>
<b>Position Class - Tailwind CSS </b>
<div class="w-3/4 bg-red-200 h-24 overflow-auto">
<div>
<div class="p-2 sticky top-0 bg-red-500 text-right">
Sticky Heading - 1
</div>
<p class="py-4">
How frequently were you baffled while
paying special attention to a decent assortment of
programming/calculation/inquiries questions?
What did you expect and what did you get?
This entrance has been made to give
elegantly composed, very much idea and 
well-clarified answers for chosen questions.
</p>


</div>
<div>
<div class="p-2 sticky top-0 bg-red-500 text-right">
Sticky Heading - 2
</div>
<p class="py-4">
How frequently were you baffled while
paying special attention to a decent assortment of
programming/calculation/inquiries questions?
What did you expect and what did you get?
This entrance has been made to give
elegantly composed, very much idea and 
well-clarified answers for chosen questions.


</p>


</div>
<div>
<div class="p-2 sticky top-0 bg-red-500 text-right">
Sticky Heading - 3
</div>
<p class="py-4">
How frequently were you baffled while
paying special attention to a decent assortment of
programming/calculation/inquiries questions?
What did you expect and what did you get?
This entrance has been made to give
elegantly composed, very much idea and 
well-clarified answers for chosen questions.
</p>


</div>
</div>
</center>
</body>


</html>

Output (while scrolling the scrollbar we will see output like below):

Tailwind CSS Position Tailwind CSS Position Tailwind CSS Position Tailwind CSS Position Tailwind CSS Position


Related Topics

Tailwind CSS Order

One of the best features of Tailwind CSS is the Order class, which allows us to order flex and grid objects according to our needs. There are several different order...

2 minutes read.

Tailwind CSS Clear

This class acknowledges more than one worth in tailwind CSS. Every one of the properties is canvassed as in class form. It is an option in contrast to the CSS...

5 minutes read.

Tailwind CSS Gap

In tailwind CSS, this class accepts multiple values, and all of the properties are covered in class form. It's a replacement for the CSS gap attribute. This class is used...

4 minutes read.

Tailwind CSS Align Items

In tailwind CSS, this class accepts a wide range of values. It's a replacement for the CSS Align Items attribute. This class is used to align things within the flexible...

5 minutes read.

Tailwind CSS Padding

This class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS Padding Property. This class is used...

4 minutes read.

Tailwind CSS Box Shadow

The Tailwind CSS Box Shadow class accepts a lot of value, and all of the properties are covered in class form. We may control the box-shadow of an element by...

2 minutes read.

Tailwind CSS Grid Auto Rows

In tailwind CSS, this class takes multiple values and covers all of the properties in class form. It's a replacement for the grid-auto-rows CSS attribute. The size of the rows...

6 minutes read.

Tailwind CSS Align Self

This class accepts a wide range of values. It's a replacement for the CSS Align Self attribute. This class is used to control how a flex or grid item is...

4 minutes read.

Tailwind CSS Margin

The margin class accepts a large number of values, and all of the properties are covered in the same way they are in the class form. It's a replacement for...

6 minutes read.

Tailwind CSS Place Items

This class accepts a wide range of values. It's a replacement for the CSS Place Items property. This class is used to manage how things are justified while still being...

4 minutes read.

Tailwind CSS Justify Self

The class form goes over the various properties. It's a replacement for the CSS justify-self attribute. This class is used to describe the alignment of content’s position in a CSS...

4 minutes read.

Tailwind CSS tutorial

Tailwind CSS can be utilized to make sites in the quickest and the least demanding way. Tailwind CSS is the most famous utility-first CSS structure on the planet for quickly...

4 minutes read.

Tailwind CSS Grid Column Start / End

This class accepts multiple values, and all of the properties are covered in class form. It was used as a replacement to the CSS grid-column property in CSS to express...

3 minutes read.

Tailwind CSS Height

This class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS height property. This class is used...

4 minutes read.

Tailwind CSS Justify Content

In tailwind CSS, this class accepts two values. It's a replacement for CSS's justify-content attribute. This class is used to describe the flexible box container's alignment. Along the main axis...

4 minutes read.

Tailwind CSS Flex Shrink

CSS flexbox is an important element for frontend development. There are two flex-shrink options in Tailwind CSS, and all properties are covered in class form. For quick front-end development, it's...

3 minutes read.

Tailwind CSS Installation

Here, we will discuss the installation method of Tailwind CSS using two strategies discussed as follows: Strategy 1: Install Tailwind through npm Step 1: npm init - y Step 2: npm install tailwindcss Step...

2 minutes read.

Tailwind CSS Flex

CSS flexbox is an important component for frontend development. There are four flex options in Tailwind CSS, and all of the attributes are covered in class form. It's a front-end...

6 minutes read.

Tailwind CSS Stroke

This class accepts a lot of value, and all of the properties are covered in class form. It's the stroke class that goes on top of the SVG element. Stroke...

2 minutes read.

Tailwind CSS Min-Width

In tailwind CSS, this class accepts a large number of values, and all of the properties are covered in class form. It's a replacement for the CSS min-width property. This...

1 minute read.