css 小經驗: 垂直,上下定高,中間自適應

來源:互聯網
上載者:User

  今天因需求做了個css樣式,要求一個div中,上下高度固定,中間自適應。

  下面見樣碼:

<div id=container> <div id="top">上部固定高度100px</div> <div id="middle">中部自適應高度</div> <div id="bottom">底部固定高度100px</div></div>

 

/*  css file */#container{ width: 100%; height: 100%; position: relative;}#top{ width: 100%; height: 100px; position: absolute; top: 0; left:0;}#middle{ width: 100%; height: 100px; position: absolute; //使用絕對位置來實現自適應 top: 100px; bottom:100px;}#bottom{ width: 100%; height:100px; position:absolute; bottom: 0; left: 0;}
相關文章

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.