CSS Data Type - <display-inside>



CSS <display-inside> data type determines the inner display of an element, which specifies the formatting context type, for a non-replaced element. These keywords define values for the display property. They can be used as a single keyword for older versions of browsers or along with a value from the <display-outside> keywords.

Possible Values

  • flow-root − It creates a new block formatting context for an element.

  • table − The element itself becomes a block-level container that behaves like an HTML table.

  • flex − The element works as a block-level element and arranges its content based on the flexbox model.

  • grid − The element works as a block-level element and arranges its content based on the grid model.

Syntax

<display-inside>: flow-root | table | flex | grid;

CSS <display-inside> - flow-root

The following example demonstrates that the display: flow-root property creates a block formatting context and contains the floated elements −

<html>
<head>
<style>
   .container {
      display: flow-root;
      border: 2px solid blue;
      padding: 10px;
   }
   .float-left {
      float: left;
      height: 30px;
      width: 50%;
      background-color: pink;
   }
   .float-right {
      float: right;
      height: 30px;
      width: 50%;
      background-color: yellow;
   }
</style>
</head>
<body>
   <div class="container">
      <div class="float-left">Floating Left</div>
      <div class="float-right">Floating Right</div>
   </div>
</body>
</html>

CSS <display-inside> - table

The following example demonstrates that display: table property defines an element as a table −

<html>
<head>
<style>
   .table-container {
      display: table;
      width: 100%;
      border-collapse: collapse;
      background-color: pink;
   }
   .row {
      display: table-row;
   }
   .column {
      display: table-cell;
      border: 2px solid blue;
      padding: 5px;
   }
</style>
</head>
<body>
   <div class="table-container">
      <div class="row">
         <div class="column">Row 1, Column 1</div>
         <div class="column">Row 1, Column 2</div>
         <div class="column">Row 1, Column 3</div>
      </div>
      <div class="row">
         <div class="column">Row 2, Column 1</div>
         <div class="column">Row 2, Column 2</div>
         <div class="column">Row 2, Column 3</div>
      </div>
   </div>
</body>
</html>

CSS <display-inside> - flex

The following example demonstrates that display: table property defines an element as a table element −

<html>
<head>
<style>
   .flex-container {
      display: flex; 
      align-items: center; 
      height: 50px; 
      padding: 5px;
      gap: 5px;
      background-color: red;
   }
   .flex-item {
      padding: 10px;
      border: 2px solid green;
      background-color: yellow;
   }
</style>
</head>
<body>
   <div class="flex-container">
      <div class="flex-item">Flex Item 1</div>
      <div class="flex-item">Flex Item 2</div>
      <div class="flex-item">Flex Item 3</div>
   </div>
</body>
</html>

CSS <display-inside> - grid

The following example demonstrates that the display: grid property creates a basic grid layout with three columns and two rows −

<html>
<head>
<style>
   .grid-container {
      display: grid;
      grid-template-columns: 100px 100px 100px; 
      grid-template-rows: 50px 50px; 
      gap: 5px; 
      align-items: center;
      background-color: pink;
      padding: 5px;
   }
   .grid-item {
      background-color: yellow;
      padding: 10px;
      text-align: center;
      border: 3px solid red;
   }
</style>
</head>
<body>
   <div class="grid-container">
      <div class="grid-item">Grid Item 1</div>
      <div class="grid-item">Grid Item 2</div>
      <div class="grid-item">Grid Item 3</div>
      <div class="grid-item">Grid Item 4</div>
      <div class="grid-item">Grid Item 5</div>
      <div class="grid-item">Grid Item 6</div>
   </div>
</body>
</html>
Advertisements