css中flex:1彈性布局例子

來源:互聯網
上載者:User
<!DOCTYPE html><html><head><meta charset="utf-8"><style>#main {    width: 220px;    height: 300px;    border: 1px solid black;    display: -webkit-flex; /* Safari */    -webkit-align-items: center; /* Safari 7.0+ */    display: flex;    align-items: center;}#main div {   -webkit-flex: 1; /* Safari 6.1+ */   flex: 1;}</style></head><body><div id="main">   <div style="background-color:lightblue;">BLUE</div>  <div style="background-color:lightgreen;">Green div with more content.</div>       RED </div></body></html> 

注意事項:

1.flex必須在彈性模組中有效,即display:flex

2.如上例RED沒有參與flex分配,所以藍色和綠色平均分配除RED後的剩餘空間

相關文章

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.