Detailed explanation of the difference between flex and inline-flex in CSS

Detailed explanation of the difference between flex and inline-flex in CSS

inline-flex is the same as inline-block. It is a display:flex container for internal elements and an inline block for external elements.

Description of the difference between the two:

  • flex: Display the object as an elastic box
  • inline-flex: Displays the object as an inline block-level flexible box

In one sentence, when the Flex Box container does not set a width size limit, when display is specified as flex, the width of the FlexBox will fill the parent container, and when display is specified as inline-flex, the width of the FlexBox will wrap the child Item, as shown in the following figure:

The corresponding code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>

  <style>

    /*Flex container*/
    .flex__container {
      display: inline-flex;
      background-color: gray;
    }

    /*Flex sub-item */
    .flex__item {
      width: 50px;
      height: 50px;

      background-color: aqua;
      border: 1px solid black;
    }

  </style>
</head>
<body>

<!--Flex container-->
<div class="flex__container">

  <!--Sub-Item in Flex container-->
  <div class="flex__item"></div>
  <div class="flex__item"></div>
  <div class="flex__item"></div>
  <div class="flex__item"></div>
</div>

</body>
</html>

This concludes this article on the differences between flex and inline-flex in CSS. For more information about CSS flex and inline-flex, please search previous articles on 123WORDPRESS.COM or continue browsing the related articles below. I hope you will support 123WORDPRESS.COM in the future!

<<:  Use of MySQL trigger

>>:  An article teaches you how to use Vue's watch listener

Recommend

ElementUI component el-dropdown (pitfall)

Select and change: click to display the current v...

How to connect to docker server using ssh

When I first came into contact with docker, I was...

js regular expression lookahead and lookbehind and non-capturing grouping

Table of contents Combining lookahead and lookbeh...

Detailed steps to modify MySQL stored procedures

Preface In actual development, business requireme...

Web front-end performance optimization

Web front-end optimization best practices: conten...

Axios project with 77.9K GitHub repository: What are the things worth learning?

Table of contents Preface 1. Introduction to Axio...

XHTML tutorial, a brief introduction to the basics of XHTML

<br />This article will briefly introduce yo...

MySQL 8.0.12 Simple Installation Tutorial

This article shares the installation tutorial of ...

How to install MySQL server community version MySQL 5.7.22 winx64 in win10

Download: http://dev.mysql.com/downloads/mysql/ U...

Disable autocomplete in html so it doesn't show history

The input box always displays the input history wh...

Graphic tutorial on installing CentOS7 on VMware 15.5

1. Create a new virtual machine in VMware 15.5 1....

jQuery implements employee management registration page

This article example shares the specific code of ...