JS基礎 — JavaScript常用的 Object 方法
JS基礎 — JavaScript常用的 Number 方法
JS進階 — 建構函式 Object & Constructor
JS基礎 — JavaScript常用的 Array 方法
前端設計 — SCSS常用函式
前端設計 — SCSS基礎語法
前端設計 — 表單(form)元件
前端設計 — 置中方法整理
前端設計 — 置中方法整理
Display 屬性置中
📌 Display: block
1 | <div class="outter outter1"> |
1 | .outter.outter1 .box1{ |
📌 Display: inline-block
1 | <div class="outter outter1"> |
1 | .outter.outter1{ |
📌 Display: flex
搭配 justify-content
,對子層做水平置中
1 | <div class="outter outter1"> |
1 | .outter.outter1{ |
搭配 margin
-
margin: 0 auto;
1
2
3
4
5
6
7
8
9.outter.outter1{
display: flex;
/* 先使子層由左至右排列 */
}
.box1{
margin:0 auto;
/*再針對box本身做置中,此例為margin:0 auto*/
} -
margin: auto auto;
1
2
3
4
5
6
7
8
9.outter.outter1{
display: flex;
/* 先使子層由左至右排列 */
}
.box1{
margin: auto auto;
/* 再針對box本身做置中,此例會在outter3-3"正中間"! */
}
搭配 align-items
1 | .outter.outter1{ |
搭配 align-self
1 | .outter.outter1{ |
搭配 flex-direction
-
垂直置中
1
2
3
4
5
6
7
8.outter.outter1{
display: flex;
/* 使子層由左到右排列 */
flex-direction: column;
/* 使子層由上向下排列 */
justify-content: center;
/* 方向被flex-direction轉換為控制"垂直"方向 */
} -
水平置中
1
2
3
4
5
6
7
8.outter.outter1{
display: flex;
/* 使子層由左到右排列 */
flex-direction: column;
/* 使子層由上向下排列 */
align-items: center;
/* 方向被flex-direction轉換為控制"水平"方向 */
} -
正中間
1
2
3
4
5
6
7
8
9
10.outter.outter1{
display: flex;
/* 使子層由左到右排列 */
flex-direction: column;
/* 使子層由上向下排列 */
justify-content: center;
/* 方向被flex-direction轉換為控制"垂直"方向 */
align-items: center;
/* 方向被flex-direction轉換為控制"水平"方向 */
}
📌 Position 屬性置中
1 | .outter.outter1{ |
📌 文字的置中
1 | /* 完全置中於box的正中間 */ |