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
- <div class="parent">
- <header> North </header>
- <aside class="left"> East </aside>
- <div class="center"> </div>
- <aside class="Righ"> West </aside>
- <footer> South </footer>
- </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
- . parent{
- Display:flex;
- flex-Direction:row;
- Flex-wrap:wrap;
- text-align: Center;
- }
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
- HEADER,&NBSP;FOOTER{&NBSP;&NBSP;
- Flex-basis: 100%;&NBSP;&NBSP;
- }&NBSP;&NBSP;
- . CENTER{&NBSP;&NBSP;
- flex-grow: 3;&NBSP;&NBSP;
- }
- ASIDE{&NBSP;&NBSP;
- flex-grow:1;&NBSP;&NBSP;
- }
这样就实现了BorderLayout布局,是不是非常简单.不要忘记了,要给他们设定相应的高度,和背景色,不然看到的是一片白,以为没反应呢!我是这样设置的,作为参考
[CSS]View Plaincopy
- . parent{
- Display:flex;
- flex-Direction:row;
- Flex-wrap:wrap;
- text-align: Center;
- }
- Header,footer,aside,. center{
- padding: 10px;;
- }
- . center,aside{
- min-height: 300px;
- }
- Header, footer{
- Flex-basis: 100%;
- min-height: 80px;
- }
- header{
- Background-color:cadetblue;
- }
- footer{
- Background-color:darkgrey;
- }
- . center{
- Flex-grow: 3;
- }
- aside{
- Flex-grow:1;
- Background-color:bisque;
- }
最后测试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