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

A brief discussion on Yahoo's 35 rules for front-end optimization

Abstract: Whether at work or in an interview, opt...

A brief introduction to MySQL InnoDB ReplicaSet

Table of contents 01 Introduction to InnoDB Repli...

Example code for implementing a hollow mask layer with CSS

Contents of this article: Page hollow mask layer,...

The button has a gray border that is ugly. How to remove it?

I used the dialog in closure and drew a dialog wit...

WeChat applet uses the video player video component

This article example shares the specific code of ...

jQuery implements Table paging effect

This article shares the specific code of jQuery t...

Mysql 5.7.18 Using MySQL proxies_priv to implement similar user group management

Use MySQL proxies_priv (simulated role) to implem...

MySQL master-slave replication principle and points to note

Written in front I have been writing a special to...

7 ways to vertically center elements with CSS

【1】Know the width and height of the centered elem...

How to configure mysql on ubuntu server and implement remote connection

Server: Ubuntu Server 16.04 LSS Client: Ubuntu 16...

Vue encapsulates the public function method of exporting Excel data

vue+element UI encapsulates a public function to ...

Detailed explanation of Vue3's responsive principle

Table of contents Review of Vue2 responsive princ...

CenterOS7 installation and configuration environment jdk1.8 tutorial

1. Uninstall the JDK that comes with centeros fir...

Solve the problem of the container showing Exited (0) after docker run

I made a Dockerfile for openresty on centos7 and ...