Open In App

How to Remove Display Flex in CSS?

Last Updated : 24 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

We use "display flex" property in our CSS code to create a flexible layout. To remove display flex in CSS, We can simply set the display property of the particular element to another value like we can set "flex" to "block" or "inline-block" for our needs.

These are the following approaches to remove display flex in CSS:

Using "display: block" property

  • First, create a basic HTML structure then inside the <body> tag, add a div element with the class "container" or you can use any other class also.
  • Inside the main div create some other divs for showing properly to remove the display flex property.
  • To remove the display: flex in your code use display: block.

Example: The example code below shows how to remove display flex in CSS using display: block.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width,
                   initial-scale=1.0">
    <title>Display Block Example</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="container">
        <div class="element">Item 1</div>
        <div class="element">Item 2</div>
        <div class="element">Item 3</div>
    </div>
</body>

</html>
CSS
.container {
    background-color: #f0f0f0;
    padding: 20px;
    width: 35vw;
    margin-left: 25rem;
    margin-top: 10rem;
}

.element {
    background-color: #4CAF50;
    color: white;
    margin: 10px 0;
    padding: 20px;
    display: block;
    /* It is helps to remove display: flex */
}

Output:

Screenshot-_521_
Output1

Using "display: inline-block" property

  • First, create a basic HTML structure then inside the <body> tag, add a div element with the class "container" or you can use any other class also.
  • And inside the main div create some other divs for showing properly to remove display flex property.
  • To remove the display:flex in your code use display: inline-block.

Example: The example code below shows how to remove display flex in CSS using display: inline-block.

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" 
          content="width=device-width,
                   initial-scale=1.0">
    <title>Display Inline-Block Example</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="container">
        <div class="element">Item 1</div>
        <div class="element">Item 2</div>
        <div class="element">Item 3</div>
    </div>
</body>

</html>
CSS
.container {
    background-color: #f0f0f0;
    padding: 20px;
    width: 35vw;
    margin-left: 25rem;
    margin-top: 10rem;
}

.element {
    background-color: #2196F3;
    color: white;
    margin: 10px;
    padding: 20px;
    display: inline-block;
    /* It is helps to remove display: flex */
}

Output:

Screenshot-_523_
Output2

Master JavaScript with our full Javascript - Beginner to Advanced online course! From basics to advanced techniques, build interactive websites and earn a certification. Take the Three 90 Challenge—complete 90% in 90 days for a 90% refund. Start now and unlock your JavaScript potential!


Similar Reads

What is the difference between display:inline-flex and display:flex in CSS ?
In this article, we will see the display property & its values, i.e. the inline-flex & flex, in order to specify the display behavior of an element, along with understanding their basic differences & will illustrate them through the examples. Both CSS display: inline-flex and display: flex properties are used to create flexible layouts.
3 min read
Bulma Flex grow and flex shrink
Bulma is an Open source CSS framework developed by Jeremy Thomas. This framework is based on the CSS Flexbox property. It is highly responsive, minimizing the use of media queries for responsive behavior. In this article, we will learn about Bulma flex-grow and flex-shrink properties. The Bulma framework allows the users to use CSS flex-shrink and
2 min read
Bootstrap 5 Flex Enable Flex Behaviors
Bootstrap 5 Enable Flex Behaviors are used to apply display utilities to create a flexbox container and transform direct children elements into flex items. With more flex properties, flex items and containers can be further modified. Utility classes: .d-flex: It displays an element as a flex container..d-inline-flex: It displays an element as an in
2 min read
How to Center a Flex Container but Left-Align Flex Items?
When we use CSS Flexbox, we might encounter situations where we want to center a flex container within its parent while keeping the flex items inside it left-aligned. This interface is very common in web design to create balanced and visually appealing interfaces. Below are different approaches to center a flex container but left-align flex items:T
4 min read
How to Set a Flex Container to Match the Width of Its Flex Items?
Flexbox is a powerful layout model in CSS that simplifies the process of designing responsive layouts. One common scenario is needing the flex container to dynamically adjust its width to match the combined width of its flex items. By default, flex containers expand to fill the available space, but with the right techniques, we can ensure that the
2 min read
What is Display Flex in CSS?
In CSS, display: flex; is a value of the display property that enables the flexible layout model for arranging the elements in a container. When you can apply the display: flex; to the container element, it can become the flex container and its direct children become the flex items. This layout model allows you to distribute the space within the co
5 min read
What is the difference between display: inline and display: inline-block in CSS?
The display property in CSS is a very useful and commonly used property that contains many values. The display property defines how an HTML element should be displayed on the webpage. The property also specifies the type of box used for an HTML element and how it should be laid out on the page. If we need to display the elements that are laid out a
4 min read
How display: inline is different from display: inline-block in CSS ?
In this article, we will know about the display property in CSS, along with understanding the 2 different property values for display property, i.e., display: inline & display: inline-block properties, & will understand their basic differences & implementation through the examples. The display property facilitates setting the element by
3 min read
What is the difference between inline-flex and inline-block in CSS?
The display property specifies how an element should be displayed on a webpage. There can be many values, related to this property in CSS. Inline-block and inline-flex are two such properties. Although there are several values that this property can have, to understand the aforementioned, let us first look into three other values: inline, block, an
3 min read
CSS | Ordering Flex Items
The order property of CSS can be used for ordering flex items. It specifies the order of a flex item with respect to the other flex items. The element has to be a flexible item for the order property to work. The elements are displayed in ascending order of their order values. If two elements have the same order value then they are displayed on the
2 min read
  翻译: