ããã«ã¡ã¯ãcrowdworks.jp ã§ã¨ã³ã¸ãã¢ããã¦ãã @t0yohei ã§ããæè¿ã¯ãã¶ã¤ã³ã·ã¹ãã æ§ç¯ã®ä¸è²«ã§ã³ã³ãã¼ãã³ãã©ã¤ãã©ãªã®å®è£ ãè¡ãªã£ã¦ãã¾ãã
ä»å㯠Vue.js ã使ã£ã¦ GridSystem ãä½ãã«ã¯ã©ããããããããã©ããããã¨ãèããå¿ è¦ãããã®ãããä¼ããã¦ãããã¨æãã¾ãã
â» ãã®ããã°ã¯ã Vue Fes Japan 2023 ã®ã»ãã·ã§ã³ãVueã使ã£ã¦Grid Systemãå®è£ ãã話 ãã®å 容ãè£è¶³ããããã°ã«ãªã£ã¦ãã¾ããã»ãã·ã§ã³ãã覧ã«ãªã£ã¦ããªãæ¹ãèªãã§ãåé¡ãªãå½¢å¼ã«ãªã£ã¦ããã¾ãã®ã§ãå®å¿ãã ããã
ç®æ¬¡
- ç®æ¬¡
- ãããã GridSystem ã£ã¦ï¼
- ãã³ã©ã ãGridSystem ã¯ãªãå¿ è¦ï¼
- ãã³ã©ã ãGridSystem ã¯ãã¤ä½ããã¨ã«ãªãã
- 決ããå¿ è¦ããããã¨
- å®è£ ãã¿ã¼ã³
- å®è£ æ¹æ³
- å®è£ Tips
- çµããã«
ãããã GridSystem ã£ã¦ï¼
GridSystem 㯠1981 å¹´ã«åè¡ããããã¨ã¼ãã»ãã¥ã¼ã©ã¼ã ãããã¯ãã³ã®ä¸»èãGrid systems in graphic designãã«ã¦ä½ç³»åãããæ¦å¿µã§ãå ·ä½çã«ã¯
ã°ãªããã·ã¹ãã ã¨ã¯ãç»é¢ä¸ã«æ¶ç©ºã®ç¸¦æ¨ªç·ãã¬ã¤ãã©ã¤ã³ã¨ãã¦å¼ããããã¯ãã¨ã«æåãå³çãé ç½®ãããã¨ã§ãã¶ã¤ã³ã®ã·ã³ãã«ãªç¾ãããå¼ãåºãææ³
ã¨ããã¦ãã¾ãã
åè: ã°ãªããã·ã¹ãã ãã°ã©ãã£ãã¯ãã¶ã¤ã³ã®ããã«
å ã ããã¶ã¤ã³ã®ææ³ã§ãããããå®è£ ã¨ãã¦æ±ã GridSystem ã¯ãã®å®ç¾©ã«å®è£ ã¨ãã¦ã®å¶ç´ãå ããå¿ è¦ãããã¾ãã
å®è£ ã¨ãã¦æ±ã GridSystem ã«ã¤ãã¦æ確ãªå®ç¾©ãè¦ã¤ãããªãã£ããããä»å㯠GridSystem å®è£ ã®èµ°ãã¨è¨ãã Bootstrap ã§ã®å®ç¾©ãå ã«å®è£ ãé²ãã¦ãããã¨æãã¾ãã
ã°ãªããã·ã¹ãã ã¯ã12ã«ã©ã ã®ã·ã¹ãã ã¨5段éã®ã¬ã¹ãã³ã·ããSassã¨mixinãããã¤ãã®å®ç¾©ãããã¯ã©ã¹ã§ãã¹ã¦ã®å³å½¢ã¨ãµã¤ãºã®ã¬ã¤ã¢ã¦ããä½æå¯è½ã§ãã
.
ã°ãªããã·ã¹ãã ã¯ãä¸é£ã®ã³ã³ãããè¡ãåã使ç¨ãã¦ã³ã³ãã³ããã¬ã¤ã¢ã¦ãããæ´åããã¾ãã
åè: ã°ãªããã·ã¹ãã · Bootstrap v5.3
大ã¾ãã«ã¾ã¨ãã㨠Bootstrap 風㪠GridSystem ã«ã¯ä»¥ä¸ã®ãããªæ©è½ãæ±ããããã¨è¨ãããã§ãã
- N å(ex. 12 å)ã®ã«ã©ã ã§ç»é¢ãåå²ã§ãã
- ã«ã©ã æ°ã®æå®ã§ã縦ã»æ¨ªã®ã³ã³ãã³ãã¬ã¤ã¢ã¦ããå¶å¾¡ã§ãã
- M 段é(ex. 5 段é)ã®ã¬ã¹ãã³ã·ããªç»é¢ã«ã§ãã
ä»åã¯ããã®è¦ä»¶ãå®ç¾ãã Bootstrap 風㮠GridSystem ãä½ãæ¹æ³ã«ã¤ãã¦è¨åãã¦ããã¾ãã ã¾ãä»å¾ GridSystem ã¨è¨ãéã¯ããã® Bootstrap 風㮠GridSystem ã®ãã¨ãæããã¨ã«ãã¾ãã
ãã³ã©ã ãGridSystem ã¯ãªãå¿ è¦ï¼
ãããã GridSystem ã¯ãªãå¿ è¦ãªã®ã§ãããããGridSystem ãå¿ è¦ã¨ãããè¦å ã¯ä»¥ä¸ã®ãããªãã®ãèãããã¾ãã
- æ ¼åç¶ã«ãã¶ã¤ã³ãããç»é¢ãå¹çããä½ããã
- CSS Grid ã Flexbox ã使ãã°å®ç¾ã§ãããã©ãç»é¢å ¨ä½ããµã¼ãã¹å ¨ä½ã§çµ±ä¸æãæãããã
éã«ä»¥ä¸ã®è¦æããªãå ´åã¯ãGridSystem ãèªãå®è£ ããã GridSystem ã使ãããã ãã« UI ã©ã¤ãã©ãªãå°å ¥ãããªã©ã¯å¿ è¦ãªãããããã¾ããã
ãã³ã©ã ãGridSystem ã¯ãã¤ä½ããã¨ã«ãªãã
UI ã©ã¤ãã©ãªãªã©ã«æ¢ã«å®è£ ããã¦ãã GridSystem ã使ããã¨ã¯æ°ããã©ãGridSystem ãèªãä½ãæ©ä¼ã¯ãã¾ããªãããããã¾ãããã§ã¯ä¸ä½ãã¤èªèº«ã§ä½ããã¨ã«ãªãã®ã§ããããã 主ã ã£ãã¿ã¤ãã³ã°ã¨ãã¦ã¯ã
- Web ãµã¼ãã¹ãä½ãä¸ã§ã®éçºæ¹éã§ãUI ã³ã³ãã¼ãã³ãã©ã¤ãã©ãªãèªä½ãããã¨ãªã£ãæ
- OSS ãªã©ã§ UI ã³ã³ãã¼ãã³ãã©ã¤ãã©ãªãä½ããã¨ããæ
- GridSystem ãèªåã§ä½ã£ã¦ã¿ãããªã¼ã¨æã£ãæ
ãªã©ãæãæµ®ãã³ã¾ãã ãããã£ãæ©ä¼ã®å¤å¯¡ã¯èªã¿æã®çããã«ä»»ããã¨ãã¦ããã®è¨äºã¯å®éã« GridSystem ãä½ããã¨ã«ãªã£ãæ¹ã«ãå°ãã§ãèªåã®ç¥è¦ãå ±æã§ããã°ã¨æãæ¸ãã¦ã¿ã¾ããã
決ããå¿ è¦ããããã¨
ãã¦ãè¥å¹²è©±ãé¸ããæ°ããã¾ãããå ·ä½çã« GridSystem ãä½ãããã«å¿ è¦ãªãã¨ã®è©±ã«å ¥ã£ã¦è¡ãã¾ãã
GridSystem ãä½ãã«ã¯ãã¾ãåºæ¬çãªãã¨ã¨ãã¦ä»¥ä¸ã®å 容ã決ããå¿ è¦ãããã¾ãã
- 対å¿ããç»é¢ãµã¤ãºã¯ä½ãã¿ã¼ã³ã«ããã
- Pc(lg), Tablet(md), Sp(sm) ãªã©
- ããããã®ç»é¢ãµã¤ãºã¯ãä½ px ã ä½ px ã¾ã§ãå²ãå½ã¦ãã
- ã¤ã¾ãç»é¢ãµã¤ãºã®å¢çå¤(breakpoint)ãä½ px ã«ããã
- ä¸åã®ç·ã«ã©ã æ°ã¯ä½ã«ã©ã ã«ããã
- ç»é¢ãµã¤ãºãã¨ã«ç·ã«ã©ã æ°ãå¤ããããçµ±ä¸ããã
ã¾ããå¿ç¨çãªå 容ã¨ãã¦ä»¥ä¸ã®ãããªãã¨ãæ¤è¨ããå¿ è¦ãããã¾ã
- ã«ã©ã éã«éé(Gutter)ãè¨ããã
- è¨ããå ´åã¯ä½ px ã«ããã
- 縦ã»æ¨ªã§ã«ã©ã éã®ééãå¥ã«ããããçµ±ä¸ããã
- GridSystem ãé©ç¨ããã¨ãªã¢(body)ã«æ大å¹
ãè¨ããã
- ã¾ããã¨ãªã¢(body)å¤ã¨ã® Margin ã¯ä½ px ã«ããã
- ã©ããã£ããªãã·ã§ã³ãç¨æããã
- Order: ã«ã©ã ã®é çªãå ¥ãæ¿ããããã®ãªãã·ã§ã³
- Offset(Start): ã«ã©ã ã®éå§ä½ç½®ãæå®ã§ããããã«ããããã®ãªãã·ã§ã³
- etc...
決ãããã¨ãå¤ãã§ãããèªå(é)ãå¿ è¦ã¨ãã GridSystem ã¯ã©ããããã®ãã調æ»ã»è°è«ããªããå®ç¾©ãã¦ããã¾ãã
åèã¾ã§ã«ãcrowdworks.jp ã® GridSystem ã«ããã¦ãå®éã«æ±ºããå 容ã¯ä»¥ä¸ã®ãããªãã®ã«ãªãã¾ã(ã¾ã ã¾ã çºå±ä¸ã®ãããå¾ããå¤æ´ã«ãªãå ´åãããã¾ã)ã
ã¾ããGridSystem ã®æ¤è¨ã«ããã£ã¦ã¯å®éã«éç¨ããã¦ãã GridSystem ã調æ»ãã¦ã¿ããã¨ãéè¦ã«ãªããããç§éãåèã«ããã¦ããã£ã GridSystem ããã¤ããç´¹ä»ããã¦é ãã¾ãã
å®è£ ãã¿ã¼ã³
GridSystem ã®å®è£ ã«ã¯å¤§ãã以ä¸ã® 3 ã¤ã®å®è£ ãã¿ã¼ã³ãããã¾ãã
- float ã使ãæ¹æ³
- Flexbox ã使ãæ¹æ³
- CSS Grid ã使ãæ¹æ³
æ´å²çã«ã¯ float ã使ãæ¹æ³ãä¸çªå¤ãã次㫠FlexBox ã使ãæ¹æ³ãCSS Grid ã使ãæ¹æ³ã¨ä¸¦ãã§ãã¾ãã
Bootstrap ã§ã¯ã3 ç³»ã¾ã§ã¯ float ã使ãæ¹æ³ã§ã4 ç³»ãã㯠Flexbox ã使ãæ¹æ³ã5 ç³»ãã㯠CSS Grid ã使ãæ¹æ³ãç»å ´ãã¦æ¥ã¾ã(5 ç³»ã§ã¯ Flexbox ã使ãæ¹æ³ãCSS Grid ã使ãæ¹æ³ã®ä¸¡æ¹ãæä¾ããã¦ãã¾ã)ã Bootstrap ã®é²åã¯ãã£ã±ããããã§ããã
- Grid system · Bootstrap v3.4
- Grid system · Bootstrap v4.0
- Grid system · Bootstrap v5.2
- CSS Grid · Bootstrap v5.2
Bootstrap 風㮠GridSystem ãä½ãã®ã§ããã°ãFlexbox ã使ãæ¹æ³ã§ååãªã®ã§ãããä»åã¯ãã£ãããªã®ã§ CSS Grid ã使ãæ¹æ³ã§ GridSystem ãä½ã£ã¦ããã¾ãã
å®è£ æ¹æ³
å®è£ æ¹æ³ã«ã¤ãã¦ã¯ãä¸è¨ã¹ã©ã¤ãã«ã¦ç»é¢ã®è¡¨ç¤ºã交ããªããç´¹ä»ãè¡ãªãã¾ããã ããã§ç´¹ä»ãã¦ãã GridSystem ã«èä»ããè¡ãªã£ã¦ãããã¨ã§ãéç¨å¯è½ãª GridSystem ãä½ããã¨ãã§ããã¨æãã¾ãã speakerdeck.com
å®è£ Tips
æéã®é½åä¸ãã¹ã©ã¤ãã«è¨è¼ã§ããªãã£ãå®è£ Tips ãããã¤ããç´¹ä»ãã¾ãã
GridLayoutFrame ã³ã³ãã¼ãã³ã
GridSystem ãé©ç¨ããã¨ãªã¢(body)ã®æå¤§å¹ ã¨ãã¨ãªã¢(body)å¤ã¨ã® margin ãè¨å®ããããã® Layout ã³ã³ãã¼ãã³ãã§ãã å®è£ ã¯ä»¥ä¸ã®ãããªã¤ã¡ã¼ã¸ã«ãªãã¾ãã
<template> <div class="grid-layout-frame"> <slot /> </div> </template> <style scoped> .grid-layout-frame { max-width: 1200px; margin-right: auto; margin-left: auto; } @media screen and (width <= 1279px) { .grid-layout-frame { max-width: 575px; margin-right: auto; margin-left: auto; } } @media screen and (width <= 607px) { .grid-layout-frame { margin-right: 16px; margin-left: 16px; } } </style>
index.ts ã§ã® import and export
ä¾ãã°ãcomponents/layouts/grid_system
ã«ã¦ GridSystem é¢é£ã®ã³ã³ãã¼ãã³ããå®è£
ãã¦ããå ´åã components/layouts/grid_system/index.ts
ãä½æã以ä¸ã®ããã«å®è£
ãããã¨ã§ãå®éã«ä½¿ãéã® import ãç°¡æ½ã«ãªãã¾ãã
import GridColumn from './GridColumn.vue'; import GridLayout from './GridLayout.vue'; import GridLayoutFrame from './GridLayoutFrame.vue'; export { GridColumn, GridLayout, GridLayoutFrame };
JS ã®ã©ã¤ãã©ãªãªã©ã§ãã使ããã¦ããããæ¹ã§ããã
æçµçãªå®è£ ã¤ã¡ã¼ã¸
GridSystem ãé©ç¨ããç»é¢ã§ä¸è¬çã«è¡ãå®è£ ã¯æ¬¡ã®ããã«ãªãã¾ãã
<script> import { GridLayoutFrame, GridLayout, GridColumn } from '@/components/layouts/grid_system'; </script> <template> <GridLayoutFrame> <GridLayout> <GridColumn :pc="12" :tbl="12" :sp="12"> ã°ãªããå ¨ä½ã«ã¾ãããè¦ç´ </GridColumn> </GridLayout> <GridLayout> <GridColumn :pc="3" :tbl="12" :sp="12"> ãµã¤ããã¼ </GridColumn> <GridColumn :pc="9" :tbl="12" :sp="12"> ã¡ã¤ã³ã³ã³ãã³ã </GridColumn> </GridLayout> </GridLayoutFrame> </template>
ç°¡æ½ã§è¯ãæãã§ããï¼
çµããã«
GridSystem 㯠CSS Grid ã®ç»å ´ããSubgrid ãéã«å ¨ã¡ã¸ã£ã¼ãã©ã¦ã¶ã«å®è£ ããããã¨ã«ãããæ´ãªãé²åãéããäºæããã¦ãã¾ãã Bootstrap 風㮠GridSystem ã¯æ´å²çãªçµç·¯ã«ããã縦ã®ç»é¢å²ããã¼ã¹ã¨ãã GridSystem ã«ãªã£ã¦ãããCSS Grid ãªã©ãæä¾ãã縦横ã«æè»ãªç»é¢é ç½®ã¨ã¯ã¾ãéã£ããã®ã«ãªã£ã¦ãã¾ãã
ãããã£ãçµç·¯ããããã©ã®ãã㪠GridSystem ã主æµã¨ãªã£ã¦ãããä»å¾ã楽ãã¿ã§ããã
ããã§ã¯ã以ä¸ã§ãã®è¨äºãç· ãããã¦ããã ããã°ã¨æãã¾ããæå¾ã¾ã§èªãã§é ããããã¨ããããã¾ããã
*1:ããã¾ã§ Bootstrap 風㪠GridSystem ãå®è£ ããéã«æ±ããããè¦ä»¶ã§ããå ã® GridSystem ã®å®ç¾©ãå¥ã®è§£éã§å®è£ ã«è½ã¨ãè¾¼ãå ´åã¯ãå¥ã®æ©è½è¦ä»¶ã«ãªãã¾ãã