<divclass="container"> <divclass="row"> <!-- 1 --> <divclass="col"> <divclass="item"> <imgsrc='https://picsum.photos/300/200?random=10'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div> <!-- 2 --> <divclass="col"> <divclass="item"> <imgsrc='https://picsum.photos/300/200?random=15'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div> <!-- 3 --> <divclass="col"> <divclass="item"> <imgsrc='https://picsum.photos/300/200?random=20'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div> <!-- 4 --> <divclass="col"> <divclass="item"> <imgsrc='https://picsum.photos/300/200?random=20'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div> <!-- 5 --> <divclass="col"> <divclass="item"> <imgsrc='https://picsum.photos/300/200?random=20'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div> </div> </div>
固定寬度的格線用法 col-4
格線系統是將空間分割成 12 欄,分割成 12 等分。
所以假如要放 3 個 column,就使用 12/4=3,col-4,4 為三個 div 各獲得 4 個空間。
<!-- 每一個元素佔12/4=3格 --> <divclass="col-4"> <divclass="item"> <imgsrc='https://picsum.photos/300/200?random=10'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div> <divclass="col-4"> <divclass="item"> <!-- w-100 寬度100% --> <imgsrc='https://picsum.photos/300/200?random=15'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div> <divclass="col-4"> <divclass="item"> <imgsrc='https://picsum.photos/300/200?random=20'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div>
<divclass="col-12 col-md-4 col-lg-3 col-xxl-2"> <divclass="item"> <imgsrc='https://picsum.photos/300/200?random=65'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div>
自動欄寬 RWD 應用
全部設定為只有 col。
直接在 row 上面動手腳,一樣可以達到效果。
1 2 3 4 5 6 7 8 9
<divclass="row row-cols-md-3 row-cols-lg-4 row-cols-xxl-6"> <!-- col在不同的裝置上面,有不同的設定,不同的欄寬數。 --> <!-- 希望在平板上面有作用 --> <divclass="col-md"> <divclass="item"> <imgsrc='https://picsum.photos/300/200?random=10'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div>
控制欄位的間距
g-為欄中間的間距,也可以設定g-0,就不會有空間。
1 2 3 4 5 6 7 8
<divclass="g-5 row row-cols-md-3 row-cols-lg-4 row-cols-xxl-6"> <divclass="col-md"> <divclass="item"> <imgsrc='https://picsum.photos/300/200?random=10'class="w-100"> <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Voluptas corrupti, delectus minima ipsum ipsam laborum vero deleniti sint recusandae? Et libero ea beatae quod est dolorum hic excepturi totam exercitationem?</p> </div> </div> </div>