響應式佈局:CSS-flexbox & Bootstrap
來源:https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox
https://www.oschina.net/translate/boostrap-4-regular-vs-flex-grid?cmp
這個靈活的盒子模組,通常被稱為flexbox,被設計成一個一維的佈局模型,作為一種方法,可以在介面中提供專案之間的空間分佈和強大的對齊功能。本文概述了flex xbox的主要特性,我們將在後面的指南中更詳細地討論這些特性。
當我們將flexbox描述為一維時,我們是在描述這樣一個事實,即flexbox每次處理一個維度的佈局——以行或列的形式。這可以與CSS網格佈局(CSS Grid Layout)的二維模型進行對比,後者將列和行一起控制。
flexbox的兩個座標軸
the main axis and the cross axis.
Start and end lines
原來的CSS都是假設從右上開始然後水平寫到左下,flexbox包含了各種書寫模式,因此我們不再假設一行文字從文件的左上角開始,然後向右側執行,新行出現在另一行下面。
After a while, thinking about start and end rather than left and right becomes natural, and will be useful to you when dealing with other layout methods such as CSS Grid Layout which follow the same patterns.
flex容器
使用flexbox佈局的文件區域稱為flex容器。要建立flex容器,我們將區域容器的display屬性的值設定為flex或inline-flex。一旦我們這樣做了,容器的直接子元素就變成了flex item。
flex items:
- Items display in a row (the
flex-direction
property's default isrow
). - The items start from the start edge of the main axis.
- The items do not stretch on the main dimension, but can shrink.
- The items will stretch to fill the size of the cross axis.
- The
flex-basis
property is set toauto
. - The
flex-wrap
property is set tonowrap
.
Multi-line flex containers with flex-wrap 多行容器
應該把每行都作為一個新的flex容器。
.box {
display: flex;
flex-wrap: wrap;
}
Properties applied to flex items
<div class="box">
<div class="one">One</div>
<div class="two">Two</div>
<div class="three">Three</div>
</div>
.box {
display: flex;
}
.one {
flex: 1 1 auto;
}
.two {
flex: 2 1 auto;
}
.three {
flex: 3 1 auto;
}
Tutorial: Styling Angular CLI v6 apps with Bootstrap
實現響應式佈局的另外一種方式-bootstrap:
<div class="container">
<div class="row">
<div class="col-4">
1 of 3
</div>
<div class="col-4">
2 of 3 (wider)
</div>
<div class="col-4">
3 of 3
</div>
</div>
</div>
.box {
display: flex;
}
.one {
flex: 1 1 auto;
}
.two {
flex: 2 1 auto;
}
.three {
flex: 3 1 auto;
}
至於用bootstrap還是自己擼CSS,網上也有討論,主要分為:
支援CSS的:
如果只是用部分功能,那麼引入bootstrap是殺雞用牛刀,讓工程變得很大;
支援bootstrap的:
bootstrap已經寫好了很多CSS,直接用就好。而且除了響應式佈局,很多其他的CSS也已經寫好了。
相關文章
- bootstrap17-響應式表格佈局boot
- bootstrap 響應式佈局 居中問題boot
- 模仿bootstrap寫響應式圖片佈局boot
- 使用BootStrap進行響應式佈局案例boot
- [開發教程]第7講:Bootstrap響應式佈局boot
- 響應式佈局
- rem響應式佈局REM
- flex彈性佈局 響應式佈局Flex
- 響應式佈局講解
- 初窺響應式佈局
- Android響應式佈局Android
- [開發教程]第9講:Bootstrap響應式佈局的實用類boot
- 響應式佈局方法總結
- [開發教程]第8講:Bootstrap把已有的固定寬度佈局轉換成響應式佈局boot
- 網頁響應式佈局的應用網頁
- 關於響應式佈局,你必須要知道關於響應式佈局的幾件事
- 移動 WEB 開發的佈局方式 ---- 響應式佈局Web
- 響應式佈局程式碼例項
- 前端響應式佈局基礎——rem前端REM
- 如何快速測試響應式佈局?
- HTML5響應式佈局案例HTML
- rem在響應式佈局中的應用REM
- 前端響應式佈局原理與實踐前端
- web響應式佈局之 meta詳解Web
- 你真的瞭解響應式佈局嗎?
- Power Apps 建立響應式佈局APP
- 移動優先的響應式佈局
- HTML5響應式佈局(簡易)HTML
- 利用bootstrap框架 實現響應式佈局阿里百秀案例以及遇到的問題!boot框架阿里
- 【探索HTML5第二彈05】響應式佈局(中),一步一步響應式佈局HTML
- bootstrap基本佈局boot
- 超 Nice 的表格響應式佈局小技巧
- 響應式佈局簡單程式碼例項
- 詳解前端響應式佈局、響應式圖片,與自制柵格系統前端
- 前端響應式佈局原理與方案(詳細版)前端
- 淺談CSS3 響應式佈局--Media QueriesCSSS3
- 前端響應式佈局為什麼是個坑?前端
- jQuery EasyUI響應式佈局的實現過程jQueryUI