×
1 Choose EITC/EITCA Certificates
2 Learn and take online exams
3 Get your IT skills certified

Confirm your IT skills and competencies under the European IT Certification framework from anywhere in the world fully online.

EITCA Academy

Digital skills attestation standard by the European IT Certification Institute aiming to support Digital Society development

SIGN IN YOUR ACCOUNT TO HAVE ACCESS TO DIFFERENT FEATURES

CREATE AN ACCOUNT FORGOT YOUR PASSWORD?

FORGOT YOUR DETAILS?

AAH, WAIT, I REMEMBER NOW!

CREATE ACCOUNT

ALREADY HAVE AN ACCOUNT?
EUROPEAN INFORMATION TECHNOLOGIES CERTIFICATION ACADEMY - ATTESTING YOUR PROFESSIONAL DIGITAL SKILLS
  • SIGN UP
  • LOGIN
  • SUPPORT

EITCA Academy

EITCA Academy

The European Information Technologies Certification Institute - EITCI ASBL

Certification Provider

EITCI Institute ASBL

Brussels, European Union

Governing European IT Certification (EITC) framework in support of the IT professionalism and Digital Society

  • CERTIFICATES
    • EITCA ACADEMIES
      • EITCA ACADEMIES CATALOGUE<
      • EITCA/CG COMPUTER GRAPHICS
      • EITCA/IS INFORMATION SECURITY
      • EITCA/BI BUSINESS INFORMATION
      • EITCA/KC KEY COMPETENCIES
      • EITCA/EG E-GOVERNMENT
      • EITCA/WD WEB DEVELOPMENT
      • EITCA/AI ARTIFICIAL INTELLIGENCE
    • EITC CERTIFICATES
      • EITC CERTIFICATES CATALOGUE<
      • COMPUTER GRAPHICS CERTIFICATES
      • WEB DESIGN CERTIFICATES
      • 3D DESIGN CERTIFICATES
      • OFFICE IT CERTIFICATES
      • BITCOIN BLOCKCHAIN CERTIFICATE
      • WORDPRESS CERTIFICATE
      • CLOUD PLATFORM CERTIFICATENEW
    • EITC CERTIFICATES
      • INTERNET CERTIFICATES
      • CRYPTOGRAPHY CERTIFICATES
      • BUSINESS IT CERTIFICATES
      • TELEWORK CERTIFICATES
      • PROGRAMMING CERTIFICATES
      • DIGITAL PORTRAIT CERTIFICATE
      • WEB DEVELOPMENT CERTIFICATES
      • DEEP LEARNING CERTIFICATESNEW
    • CERTIFICATES FOR
      • EU PUBLIC ADMINISTRATION
      • TEACHERS AND EDUCATORS
      • IT SECURITY PROFESSIONALS
      • GRAPHICS DESIGNERS & ARTISTS
      • BUSINESSMEN AND MANAGERS
      • BLOCKCHAIN DEVELOPERS
      • WEB DEVELOPERS
      • CLOUD AI EXPERTSNEW
  • FEATURED
  • SUBSIDY
  • HOW IT WORKS
  •   IT ID
  • ABOUT
  • CONTACT
  • MY ORDER
    Your current order is empty.
EITCIINSTITUTE
CERTIFIED

How does setting the `display` property to `flex` on a parent element affect the layout of its child elements?

by EITCA Academy / Monday, 19 August 2024 / Published in Web Development, EITC/WD/WFF Webflow Fundamentals, Layout, Flexbox, Examination review

Setting the `display` property to `flex` on a parent element fundamentally transforms the way its child elements are laid out. This transformation is based on the Flexbox (Flexible Box) model, which is designed to provide a more efficient way to lay out, align, and distribute space among items within a container, even when their size is unknown or dynamic. The Flexbox model is particularly beneficial for creating complex layouts and achieving responsive design.

When the `display` property of a parent element is set to `flex`, the parent element becomes a flex container, and its immediate children become flex items. This change introduces a new set of properties and behaviors that govern the layout, alignment, and distribution of the flex items within the flex container. Below, I will detail the specific effects and properties associated with the Flexbox model.

Flex Container Properties

1. `flex-direction`: This property defines the main axis along which the flex items are laid out. The main axis can be horizontal or vertical, and the `flex-direction` property can take the following values:
– `row` (default): Flex items are laid out horizontally from left to right.
– `row-reverse`: Flex items are laid out horizontally from right to left.
– `column`: Flex items are laid out vertically from top to bottom.
– `column-reverse`: Flex items are laid out vertically from bottom to top.

2. `flex-wrap`: This property controls whether the flex items should wrap onto multiple lines. It can take the following values:
– `nowrap` (default): All flex items will be laid out in a single line.
– `wrap`: Flex items will wrap onto multiple lines if necessary.
– `wrap-reverse`: Flex items will wrap onto multiple lines in reverse order.

3. `justify-content`: This property aligns flex items along the main axis and can take the following values:
– `flex-start` (default): Flex items are packed toward the start of the main axis.
– `flex-end`: Flex items are packed toward the end of the main axis.
– `center`: Flex items are centered along the main axis.
– `space-between`: Flex items are evenly distributed along the main axis with the first item at the start and the last item at the end.
– `space-around`: Flex items are evenly distributed with equal space around them.

4. `align-items`: This property aligns flex items along the cross axis (perpendicular to the main axis) and can take the following values:
– `stretch` (default): Flex items are stretched to fill the container.
– `flex-start`: Flex items are aligned at the start of the cross axis.
– `flex-end`: Flex items are aligned at the end of the cross axis.
– `center`: Flex items are centered along the cross axis.
– `baseline`: Flex items are aligned such that their baselines align.

5. `align-content`: This property aligns the flex lines (if there are multiple lines due to wrapping) along the cross axis and can take the following values:
– `stretch` (default): Lines stretch to fill the container.
– `flex-start`: Lines are packed toward the start of the cross axis.
– `flex-end`: Lines are packed toward the end of the cross axis.
– `center`: Lines are centered along the cross axis.
– `space-between`: Lines are evenly distributed with the first line at the start and the last line at the end.
– `space-around`: Lines are evenly distributed with equal space around them.

Flex Item Properties

1. `order`: This property allows you to control the order in which flex items appear within the flex container. By default, all flex items have an `order` value of 0, but you can assign positive or negative integers to change their order.

2. `flex-grow`: This property defines the ability of a flex item to grow relative to the other flex items. It is a unitless value that serves as a proportion. For example, if one flex item has a `flex-grow` value of 2 and another has a value of 1, the first item will take up twice as much space as the second item.

3. `flex-shrink`: This property defines the ability of a flex item to shrink relative to the other flex items. Similar to `flex-grow`, it is a unitless value that serves as a proportion. If space is insufficient, flex items will shrink according to their `flex-shrink` values.

4. `flex-basis`: This property defines the initial main size of a flex item before any space distribution takes place. It can be a length (e.g., `20%`, `100px`) or the keyword `auto`. The `flex-basis` property overrides the `width` or `height` properties of the flex item.

5. `align-self`: This property allows the default alignment (or the one specified by `align-items`) to be overridden for individual flex items. It can take the same values as `align-items` (`auto`, `flex-start`, `flex-end`, `center`, `baseline`, `stretch`).

Practical Examples

Example 1: Basic Horizontal Flex Layout

html
<div class="flex-container">
  <div class="flex-item">Item 1</div>
  <div class="flex-item">Item 2</div>
  <div class="flex-item">Item 3</div>
</div>

<style>
  .flex-container {
    display: flex;
    flex-direction: row;
  }
  .flex-item {
    flex: 1;
  }
</style>

In this example, the `.flex-container` is a flex container with a horizontal main axis (`flex-direction: row`). The `.flex-item` elements are flex items, each taking up an equal amount of space within the container because of the `flex: 1` shorthand property (which sets `flex-grow` to 1, `flex-shrink` to 1, and `flex-basis` to 0).

Example 2: Vertical Flex Layout with Wrapping

html
<div class="flex-container">
  <div class="flex-item">Item 1</div>
  <div class="flex-item">Item 2</div>
  <div class="flex-item">Item 3</div>
  <div class="flex-item">Item 4</div>
  <div class="flex-item">Item 5</div>
</div>

<style>
  .flex-container {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
    height: 200px;
  }
  .flex-item {
    flex: 1;
    min-height: 50px;
  }
</style>

In this example, the `.flex-container` is a flex container with a vertical main axis (`flex-direction: column`) and allows wrapping (`flex-wrap: wrap`). The `.flex-item` elements will wrap onto multiple lines if the container's height is insufficient to display all items in a single column. Each `.flex-item` has a minimum height of `50px` and will grow to fill the available space.

Advanced Flexbox Techniques

Aligning Items with `justify-content` and `align-items`

html
<div class="flex-container">
  <div class="flex-item">Item 1</div>
  <div class="flex-item">Item 2</div>
  <div class="flex-item">Item 3</div>
</div>

<style>
  .flex-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100px;
  }
  .flex-item {
    flex: 1;
  }
</style>

In this example, the `.flex-container` uses `justify-content: space-between` to evenly distribute the flex items along the main axis with space between them. The `align-items: center` property centers the flex items along the cross axis (vertically, in this case).

Changing Order with `order`

html
<div class="flex-container">
  <div class="flex-item" style="order: 2;">Item 1</div>
  <div class="flex-item" style="order: 1;">Item 2</div>
  <div class="flex-item" style="order: 3;">Item 3</div>
</div>

<style>
  .flex-container {
    display: flex;
    flex-direction: row;
  }
  .flex-item {
    flex: 1;
  }
</style>

In this example, the `order` property is used to change the visual order of the flex items. Although `Item 1` is the first element in the HTML, it will appear second due to `order: 2`. Similarly, `Item 2` will appear first (`order: 1`), and `Item 3` will appear last (`order: 3`).

The Flexbox model, when applied by setting the `display` property to `flex` on a parent element, offers a robust and versatile method for designing web layouts. It provides a wide range of properties that allow developers to control the alignment, direction, order, and size of flex items within a container, enabling the creation of complex and responsive layouts with ease. By understanding and utilizing these properties, developers can achieve precise control over the layout behavior of their web pages, ensuring that content is displayed in an optimal and visually appealing manner across different devices and screen sizes.

Other recent questions and answers regarding EITC/WD/WFF Webflow Fundamentals:

  • What are the benefits of the Preview mode in the Webflow Designer, and how does it differ from publishing the project?
  • How does the box model influence the layout of elements on the Canvas in the Webflow Designer?
  • What role does the Style panel on the right side of the Webflow Designer interface play in modifying CSS properties?
  • How does the Canvas area in the Webflow Designer facilitate real-time interaction and editing of the page content?
  • What primary functions are accessible from the left toolbar in the Webflow Designer interface?
  • What are the benefits of using a collection list when working with Multi-Reference fields in Webflow CMS?
  • How can you display the multiple contributors on a blog post page using a Multi-Reference field?
  • In what scenarios would using a Multi-Reference field be particularly beneficial?
  • What steps are involved in creating a Multi-Reference field in a CMS collection, such as Blog Posts?
  • How does a Multi-Reference field differ from a single reference field in Webflow CMS?

View more questions and answers in EITC/WD/WFF Webflow Fundamentals

More questions and answers:

  • Field: Web Development
  • Programme: EITC/WD/WFF Webflow Fundamentals (go to the certification programme)
  • Lesson: Layout (go to related lesson)
  • Topic: Flexbox (go to related topic)
  • Examination review
Tagged under: CSS, Flexbox, Frontend Development, Responsive Design, Web Design, Web Development
Home » EITC/WD/WFF Webflow Fundamentals / Examination review / Flexbox / Layout / Web Development » How does setting the `display` property to `flex` on a parent element affect the layout of its child elements?

Certification Center

USER MENU

  • My Account

CERTIFICATE CATEGORY

  • EITC Certification (106)
  • EITCA Certification (9)

What are you looking for?

  • Introduction
  • How it works?
  • EITCA Academies
  • EITCI DSJC Subsidy
  • Full EITC catalogue
  • Your order
  • Featured
  •   IT ID
  • EITCA reviews (Reddit publ.)
  • About
  • Contact
  • Cookie Policy (EU)

EITCA Academy is a part of the European IT Certification framework

The European IT Certification framework has been established in 2008 as a Europe based and vendor independent standard in widely accessible online certification of digital skills and competencies in many areas of professional digital specializations. The EITC framework is governed by the European IT Certification Institute (EITCI), a non-profit certification authority supporting information society growth and bridging the digital skills gap in the EU.

    EITCA Academy Secretary Office

    European IT Certification Institute ASBL
    Brussels, Belgium, European Union

    EITC / EITCA Certification Framework Operator
    Governing European IT Certification Standard
    Access contact form or call +32 25887351

    Follow EITCI on Twitter
    Visit EITCA Academy on Facebook
    Engage with EITCA Academy on LinkedIn
    Check out EITCI and EITCA videos on YouTube

    Funded by the European Union

    Funded by the European Regional Development Fund (ERDF) and the European Social Fund (ESF), governed by the EITCI Institute since 2008

    Information Security Policy | DSRRM and GDPR Policy | Data Protection Policy | Record of Processing Activities | HSE Policy | Anti-Corruption Policy | Modern Slavery Policy

    Automatically translate to your language

    Terms and Conditions | Privacy Policy
    Follow @EITCI
    EITCA Academy

    Your browser doesn't support the HTML5 CANVAS tag.

    • Artificial Intelligence
    • Web Development
    • Cybersecurity
    • Quantum Information
    • Cloud Computing
    • GET SOCIAL
    EITCA Academy


    © 2008-2026  European IT Certification Institute
    Brussels, Belgium, European Union

    TOP
    CHAT WITH SUPPORT
    Do you have any questions?
    We will reply here and by email. Your conversation is tracked with a support token.