CSS uses Flexbox to center multiple elements horizontally in a layout container

Source: Internet
Author: User
This article is mainly for you to detail the CSS using Flexbox layout container inside the multi-element horizontal center method, how to use the Flexbox layout multi-element horizontal center? This article for everyone to answer, interested in the small friends can refer to

You want to implement a child element in a parent element that is centered

Just add a style to the parent element

The code is as follows:

{display:flex;flex-direction:column;align-items:center;}

Set to Flexbox layout, orientation is vertical, and the third sentence is to center it.

If the distance of three child elements to set their own, set margin-top or margin-bottom just fine;

If you let it adjust automatically, you can add a style to the parent element

The code is as follows:

{justify-content:space-around;}

This allows the remaining space to be automatically assigned to the surrounding elements:)

At first I felt that there was no need to use sass, and now I find a lot of CSS code is still very reusable

For this case even save a small mixin, the default automatic adjustment, you can also pass the parameter false, do not automatically adjust

@mixin Multi-elements-center ($auto: True) {   Display:flex;   Flex-direction:column;   Align-items:center;   @if $auto {justify-content:space-around;}   }

A little progress every day, we work together to refuel, improve their technical level.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.