CSS Introduction

CSS Tutorial What is CSS CSS Syntax CSS Selector How to include CSS CSS Comments

CSS Attributes

CSS Background CSS Border CSS Display CSS Float CSS Font CSS Color CSS Hover CSS Important CSS Line-height CSS Margin CSS Opacity CSS Filter CSS Images CSS Overflow CSS Padding CSS Position CSS Vertical align CSS White space CSS Width Word-wrap in CSS Box-shadow in CSS Text-transform in CSS CSS Outline CSS Visibility CSS Counters CSS Clear fix CSS Icons CSS Justify-content Text-decoration in CSS CSS Lists CSS nth selector CSS Sticky CSS Background-clip CSS Checkbox-style CSS Letter-spacing CSS Navigation bar CSS Overlay CSS Root CSS Specificity CSS Text-indent CSS Text-stroke CSS Zoom CSS Order CSS Descendent selector CSS Clip CSS calc() CSS Background-blend-mode CSS radio-button CSS Superscript and subscript CSS Text-effects CSS Text-align CSS Variables CSS Page-break-before CSS Page-break-inside CSS Page-break-after CSS Content property CSS Word-spacing CSS Animation CSS @keyframes rules CSS Pseudo-classes CSS Pseudo-elements CSS Radial-gradient CSS Translate CSS Gradients CSS z-index CSS Loaders CSS Units CSS Transition CSS Masking CSS Arrow CSS Pagination

Misc

What is Bootstrap CSS What is CSS used for Difference between HTML and CSS How to center a table in CSS What is a CSS File How to center a button in CSS How to change background color in CSS How to change the font in CSS How to change font size in CSS How to resize an image in CSS How to get rid of bullet pioints in CSS Is CSS a programming language Grid Vs Flexbox in CSS How to edit CSS in WordPress How to use google fonts in CSS

CSS Order

CSS Order

CSS order property in CSS describes the flex item’s order inside the flex or any grid container. It is applied to order any flex item.

Note: If any component is not flexible, then CSS order will not implement.

The components will be shown in the order value’s increasing order. When two components use any same value of the order, these components will be shown according to their occurrence specified inside the code.

This CSS property changes the flex item’s visual order. The lowest order item will come first, and the higher-order item will be positioned afterward. Instead of logical or tab order, it affects only the element’s visual order. It should not be used over any non-visual media like speech.

This property allows the order’s negative values. These values are helpful if we wish to show an element first, and unchanged the other order elements. In case any value is not specified, then the 0 value will be applied, i.e., a default value. Thus, if we wish to show an element first, we may give it any negative value like -1. As -1 value is lesser than 0, any corresponding element will be displayed first always.
Syntax:

order: integer | initial | inherit;  

Property Values

This property applies the values as integer to define the item’s order.

integer: It

is applied to describe any flexible item’s order. It has a default value, i.e., 0.

initial: It sets the value of the property to its default value.

inherit: As the name suggests, the component applies any computed value from its parent component.

Let’s take some illustrations to understand this order property.

Example1:

<!DOCTYPE html>
<html>
<head>
<style>
body
{
 text-align: center;
}
.container
{
 display: flex;
 background-color: yellow;
 height: 150px;
 width: auto;
 flex-wrap: wrap;
}
div
{
 background-color: aqua;
 line-height: 40px;
 color: black;
 padding: 10px;
 text-align: center;
 font-size: 35px;
 width: 100px;
 margin: 20px;
}
</style>
</head>
<body>
<h1> Order Property </h1>
<div class= "container">
<div style= "order: 3"> 1 </div>
<div style= "order: 0"> 2 </div>
<div style= "order: 0"> 3 </div>
<div style= "order: 1"> 4 </div>
<div style= "order: -1"> 5 </div>
<div style= "order: 2"> 6 </div>
<div style= "order: 1"> 7 </div>
<div style= "order: -2"> 8 </div>
</div>
</body>
</html>

In the above illustration, we applied some negative values and few component similar order values. The component including small values are displayed first and some similar order values are displayed based on the code occurrence.

On the other hand, a div element which contains -2 order value will appear first, and the div element which contains -1 order value will appear. This process will same for all other elements.

Output:

CSS Order

Example2:

<!DOCTYPE html>
<html>
<head>
<style>
.container
{
 padding: 0;
 margin: 0;
 list-style: none;
 display: flex;
}
.list
{
 padding: 5px;
 width: 100px;
 height: 100px;
 margin: 5px;
 line-height: 100px;
 color: black;
 font-size: 30px;
 text-align: center;
}
</style>
</head>
<body>
<h2> Order Property </h2>
<ul class= "container">
<li class= "list" style= "order: 5; background-color: orange;"> 1 </li>
<li class= "list" style= "order: -1; background-color: aqua;"> 2 </li>
<li class= "list" style= "order: 1; background-color: pink;"> 3 </li>
<li class= "list" style= "order: 2; background-color: violet;"> 4 </li>
<li class= "list" style= "order: 0; background-color: tomato;"> 5 </li>
</ul>
</body>
</html>

Output:

CSS Order



ADVERTISEMENT
ADVERTISEMENT