CSS3 Flex quickly implements BorderLayout layout

Source: Internet
Author: User

After learning the flex layout pattern, we strike a boxlayout layout. What is the boxlayout layout? Let's start with a picture.

BoxLayout layout write the UI code after the end of the programmer should be unfamiliar, writing the front-end code is also familiar, including the HTML framework frame. But in the past, using float to control the CSS, control is relatively complex, but also need to add more tags and code.

After reading this interface, we can begin to write out the code layout of the tag:

[HTML]View Plaincopy
  1. <div class="parent">
  2. <header> North </header>
  3. <aside class="left"> East </aside>
  4. <div class="center"> </div>
  5. <aside class="Righ"> West </aside>
  6. <footer> South </footer>
  7. </div>

代码很简单,就只有二级关系,当然也可以将parent这一父级去掉,将body来当做父级,除非有必要.

So we started using CSS to implement BorderLayout, which also defines the parent as the Flex container, with the direction from left to right and can be wrapped.

[CSS]View Plaincopy
    1. . parent{
    2. Display:flex;
    3. flex-Direction:row;
    4. Flex-wrap:wrap;
    5. text-align: Center;
    6. }

Then set the Flex item layout mode, Header,footer we set it to flex-basis:100%, because they occupy the entire row, and the width of two aside is equal, the center is wider than the aside of the two sides, So we use Flex-grow to set their proportions.

[CSS]View Plaincopy
    1. HEADER,&NBSP;FOOTER{&NBSP;&NBSP;
    2.      Flex-basis: 100%;&NBSP;&NBSP;
    3. }&NBSP;&NBSP;
    4. . CENTER{&NBSP;&NBSP;
    5.     flex-grow: 3;&NBSP;&NBSP;
    6. }  
    7. ASIDE{&NBSP;&NBSP;
    8.     flex-grow:1;&NBSP;&NBSP;
    9. }  

这样就实现了BorderLayout布局,是不是非常简单.不要忘记了,要给他们设定相应的高度,和背景色,不然看到的是一片白,以为没反应呢!我是这样设置的,作为参考

[CSS]View Plaincopy
  1. . parent{
  2. Display:flex;
  3. flex-Direction:row;
  4. Flex-wrap:wrap;
  5. text-align: Center;
  6. }
  7. Header,footer,aside,. center{
  8. padding: 10px;;
  9. }
  10. . center,aside{
  11. min-height: 300px;
  12. }
  13. Header, footer{
  14. Flex-basis: 100%;
  15. min-height: 80px;
  16. }
  17. header{
  18. Background-color:cadetblue;
  19. }
  20. footer{
  21. Background-color:darkgrey;
  22. }
  23. . center{
  24. Flex-grow: 3;
  25. }
  26. aside{
  27. Flex-grow:1;
  28. Background-color:bisque;
  29. }

最后测试OK!

This article belongs to Wu Shi Wei's blog, the public number: Bianchengderen original article, reproduced when please indicate the source and the corresponding link: http://www.wutongwei.com/front/infor_showone.tweb?id =148, welcome everyone to spread and share.

CSS3 Flex quickly implements BorderLayout layout

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.