Webkit-box layout page instance in CSS3, css3webkit-box
Previously, the layout was calculated using float layout or display: inline-block; + width: ** %;, so it was not a real stream layout; the following example shows how to create a stream layout in CSS3 (using chrome as an example)
- Three-column Adaptive Layout
<! DOCTYPE html>
<Html>
<Meta charset = "UTF-8"/>
<Style>
. Wrap {
Display:-webkit-box;
-Webkit-box-orient: horizontal;
}
. Child {
Min-height: 200px;
Border: 2px solid #666;
-Webkit-box-flex: 1;
Margin: 10px;
Font-size: 100px;
Font-weight: bold;
Font-family: Georgia;
-Webkit-box-align: center;
}
</Style>
<Div class = "wrap">
<Div class = "child"> 1 </div>
<Div class = "child"> 2 </div>
<Div class = "child"> 3 </div>
</Div>
</Html>
- Three-column layout with a fixed width column. The remaining two columns are adaptive.
<! DOCTYPE html>
<Meta charset = "UTF-8"/>
<Style>
. Wrap {
Display:-webkit-box;
-Webkit-box-orient: horizontal;
}
. Child {
Min-height: 200px;
Border: 2px solid #666;
Margin: 10px;
Font-size: 40px;
Font-weight: bold;
Font-family: Georgia;
-Webkit-box-align: center;
}
. W200 {width: 200px}
. Flex1 {-webkit-box-flex: 1}
. Flex2 {-webkit-box-flex: 2}
</Style>
<Div class = "wrap">
<Div class = "w200 child"> 200px </div>
<Div class = "flex1 child"> ratio 1 </div>
<Div class = "flex2 child"> Ratio 2 </div>
</Div>
</Html>
- Basic layout of a common web page
<! DOCTYPE html> <meta charset = "UTF-8"/>
<Style>
Header, footer, section {
Border: 10px solid #333;
Font-family: Georgia;
Font-size: 40px;
Text-align: center;
Margin: 10px;
-Webkit-box-flex: 1;
}
# Doc {
Height: 100%;
Display:-webkit-box;
-Webkit-box-orient: vertical;
Margin: 0 auto;
}
Header, footer {
Min-height: 100px;
-Webkit-box-flex: 1;
}
# Content {
Min-height: 400px;
Display:-webkit-box;
-Webkit-box-orient: horizontal;
}
. W200 {width: 200px}
. Flex1 {-webkit-box-flex: 1}
. Flex2 {-webkit-box-flex: 2}
. Flex3 {-webkit-box-flex: 3}
</Style>
<Div id = "doc">
<Header> Header
<Div id = "content">
<Section> fixed width 200 </section>
<Section> Proportion 3 </section>
<Section> Proportion 1 </section>
</Div>
<Footer> Footer </footer>
</Div>
</Html>