<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bootstrap &#8211; Larry的午茶時光</title>
	<atom:link href="https://blog.yuyansoftware.com.tw/tag/bootstrap/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.yuyansoftware.com.tw</link>
	<description></description>
	<lastBuildDate>Tue, 21 Jan 2025 10:02:41 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.2</generator>

<image>
	<url>https://blog.yuyansoftware.com.tw/wp-content/uploads/2022/10/favicon-45x45.png</url>
	<title>Bootstrap &#8211; Larry的午茶時光</title>
	<link>https://blog.yuyansoftware.com.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Bootstrap 5.3 主要更新：深色模式 Dark mode，自訂 color mode，翻新調色盤色票，新的連結樣式</title>
		<link>https://blog.yuyansoftware.com.tw/2023/06/bootstrap-5-3-features/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Wed, 28 Jun 2023 09:40:44 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<guid isPermaLink="false">https://blog.yuyansoftware.com.tw/?p=15730</guid>

					<description><![CDATA[Bootstrap 5.3 主要是新增了深色模式 Dark mode，開發者也可以客製自己的 color mode。另外也翻新了調色盤色票 Color Palette，新增了好幾個色票。連結樣式及文件也大幅度翻新了。]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph"><a href="https://blog.getbootstrap.com/2023/05/30/bootstrap-5-3-0/" target="_blank" rel="noreferrer noopener nofollow">https://blog.getbootstrap.com/2023/05/30/bootstrap-5-3-0/</a><br>前幾個星期 (2023/5/30) Bootstrap 5.3 發布了。每次看到 Bootstrap 新版本的發布，都會有感於時間過的真的很快。以下是我關於 Bootstrap 的文章，大致的時間線：</p>



<ul class="wp-block-list">
<li>2022年7月：<a href="https://blog.yuyansoftware.com.tw/2022/07/bootstrap-5-2-features/">Bootstrap 5.2 主要更新</a></li>



<li>2021年8月：<a href="https://blog.yuyansoftware.com.tw/2021/08/bootstrap-5-1-css-grid-custom-property/">Bootstrap 5.1 主要更新</a></li>



<li>2020年12月：<a href="https://blog.yuyansoftware.com.tw/2020/12/bootstrap-5-features/">Bootstrap 5 主要更新</a></li>



<li>2018年4月：<a href="https://blog.yuyansoftware.com.tw/2018/04/bootstrap-4-flex/">Bootstrap 4 Flex</a> (那時 Bootstrap 4.1 發布)</li>



<li>2017年8月：<a href="https://blog.yuyansoftware.com.tw/2017/08/bootstrap-4-beta/">Bootstrap 4 主要更新</a></li>
</ul>



<p class="wp-block-paragraph">撰文的現在是2023年6月。可以看到每一個 minor version 的更新，就是半年～1年；major version 的更新，是好幾年一版。所以每次寫 Bootstrap，就代表好多歲月又過去了，時間真的過得太快。</p>



<p class="wp-block-paragraph">以下是 Bootstrap 5.3 的主要更新：</p>



<h2 class="wp-block-heading">深色模式 Dark mode，自訂新的 color mode</h2>



<p class="wp-block-paragraph">Bootstrap 核心已經重新設計，以支援 Dark mode。並新增了關於 Color Mode 的文件 (5.2 沒有)<br><a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.3/customize/color-modes/" target="_blank">https://getbootstrap.com/docs/5.3/customize/color-modes/</a></p>



<p class="wp-block-paragraph">Bootstrap 5.3 不但支援 Dark mode，也允許開發者設計自己的 color mode。語法上，在一開始的 html tag 下 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">data-bs-theme</mark></code>，例如</p>



<pre class="wp-block-code"><code>&lt;html lang="en" data-bs-theme="dark"&gt;
  &lt;!-- ... --&gt;
&lt;/html&gt;</code></pre>



<p class="wp-block-paragraph">你也可以在特定的元件下 color mode，例如 dropdown menu</p>



<pre class="wp-block-code"><code>&lt;div class="dropdown" data-bs-theme="dark"&gt;
  &lt;!-- ... --&gt;
&lt;/div&gt;</code></pre>



<p class="wp-block-paragraph">這樣無論上方 html tag 的 color mode，你的 dropdown menu 就會切換成 Dark mode。</p>



<p class="wp-block-paragraph">當然，如果你想要本來「亮底」的樣式，設定 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">data-bs-theme="light"</mark></code>，或是將來你自己客製的樣式。</p>



<p class="wp-block-paragraph">Light / Dark mode 都定義在 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">scss/_root.scss</mark></code>，包含如果你將來要新增自己的 color mode，也是定義在這支檔案。</p>



<p class="wp-block-paragraph">目前 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">scss/_root.scss</mark></code> 定義的是 CSS 變數，你也可以在其中指定特定元件的樣式。例如</p>



<pre class="wp-block-code"><code>@include color-mode(dark) {
  ...
  .element {
    color: var(--bs-primary-text-emphasis);
    background-color: var(--bs-primary-bg-subtle);
  }
  ...
}</code></pre>



<p class="wp-block-paragraph">另外，如果你重設這個 SCSS 變數</p>



<pre class="wp-block-code"><code>$color-mode-type: media-query; // default 是 "data"</code></pre>



<p class="wp-block-paragraph">上面那段 SCSS 會編譯成</p>



<pre class="wp-block-code"><code>@media (prefers-color-scheme: dark) {
  .element {
    color: var(--bs-primary-text-emphasis);
    background-color: var(--bs-primary-bg-subtle);
  }
}</code></pre>



<p class="wp-block-paragraph">這樣就不是 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">data-bs-theme</mark></code> 設定 scope 的概念，而是 media query <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">prefers-color-scheme</mark></code>，隨使用者作業系統調整亮/暗模式。</p>



<p class="wp-block-paragraph">有一些 Dark mode 的 CSS 變數是定義在 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">scss/_variables-dark.scss</mark></code>。當然，你可以修改再重新編譯。如果你要新增 color mode，官方文件也建議新增新的 scss 檔案，例如 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">scss/_variables-blue.scss</mark></code>。</p>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">scss/_variables-dark.scss</mark></code> 中大量的使用 Bootstrap 內建的 SCSS function <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">shade-color()</mark></code>、<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">tint-color()</mark></code>，也就是拿原始的調色盤色票去做深淺變化。如果你要整個換色系的話，修改原始色票再重新編譯，<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">scss/_variables-dark.scss</mark></code> 這支檔案就會自動幫你做深淺變化了。</p>



<h2 class="wp-block-heading">翻新調色盤色票 Color Palette</h2>



<p class="wp-block-paragraph">文件也做大幅更新，第一節 Colors 是 5.3 新增的。<br><a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.3/customize/color/" target="_blank">https://getbootstrap.com/docs/5.3/customize/color/</a></p>



<p class="wp-block-paragraph">新增 secondary、tertiary 兩個色票。舉例來說，Bootstrap 5.3 Light mode 中這幾個變數 <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">(數值是 Bootstrap 5.3 定義的，之後版本不一定會改)</mark></p>



<pre class="wp-block-code"><code>--bs-body-color-rgb: 33,37,41;
--bs-secondary-color: rgba(33, 37, 41, 0.75);
--bs-tertiary-color: rgba(33, 37, 41, 0.5);</code></pre>



<p class="wp-block-paragraph">因為是 Light mode，背景是白的，隨著 alpha 值越透明，tertiary 文字顏色最淡。</p>



<p class="wp-block-paragraph">Bootstrap 5.3 Dark mode 中這幾個變數的數值</p>



<pre class="wp-block-code"><code>--bs-body-color-rgb: 173,181,189;
--bs-secondary-color: rgba(173, 181, 189, 0.75);
--bs-tertiary-color: rgba(173, 181, 189, 0.5);</code></pre>



<p class="wp-block-paragraph">因為是 Dark mode，背景是黑的，隨著 alpha 值越透明，也就是 tertiary 文字顏色最深。</p>



<p class="wp-block-paragraph">進一步說明，以目前 (2023年6月) Bootstrap 官網文件來說，如果是 Dark mode，一般文字顏色就是 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">--bs-body-color</mark></code>，secondary / tertiary 多了兩個不同灰階 (顏色更深) 的選擇。</p>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.bg-body-secondary</mark></code>、<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.bg-body-tertiary</mark></code> 就不是深淺灰階的概念，是由 Bootstrap 直接定義值，用來搭配 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">--bs-secondary-color</mark></code>、<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">--bs-tertiary-color</mark></code> 的顏色。&nbsp;</p>



<p class="wp-block-paragraph">另外還新增 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">{color}-bg-subtle</mark></code>、<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">{color}-border-subtle</mark></code>、<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">{color}-text-emphasis</mark></code> 這幾個顏色。</p>



<p class="wp-block-paragraph">subtle 這邊指的是暗的、淡的。比如說 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.bg-success</mark></code> 是軟體操作成功的綠色，<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.bg-success-subtle</mark></code> 在 Light mode 就是淡綠色，在 Dark mode 就是墨綠色。</p>



<p class="wp-block-paragraph"><a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.3/customize/color/" target="_blank">https://getbootstrap.com/docs/5.3/customize/color/</a><br>文件也列出 Bootstrap 所有可用的色票，包含紅橙黃綠藍靛紫，以及各自的灰階，如果要很快的找一個色票使用，可以參考這裡。</p>



<h2 class="wp-block-heading">新的 Link 連結樣式</h2>



<p class="wp-block-paragraph">新的 Link 文件 (Bootstrap 5.2 沒有)，包含透明度 opacity，底線 underline 等樣式。<br><a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.3/utilities/link/" target="_blank">https://getbootstrap.com/docs/5.3/utilities/link/</a></p>



<p class="wp-block-paragraph">新的 Icon Link 文件 (Bootstrap 5.2 沒有)<br><a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.3/helpers/icon-link/" target="_blank">https://getbootstrap.com/docs/5.3/helpers/icon-link/</a></p>



<p class="wp-block-paragraph">可以輕易的在連結的前或後，加上小圖。如果再加上 css <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.icon-link-hover</mark></code>，滑鼠 hover 時小圖會有小動畫。</p>



<pre class="wp-block-code"><code>&lt;a class="icon-link icon-link-hover" href="#"&gt;
  Icon link
  &lt;svg&gt;...&lt;/svg&gt;
&lt;/a&gt;</code></pre>



<p class="wp-block-paragraph">新的 css <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.focus-ring</mark></code>，讓元件在 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">:focus</mark></code> 狀態下，不要顯示預設的 outline，而是變成 box-shadow，這樣可以更好的讓開發者客製化。</p>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.focus-ring</mark></code> 也是 Bootstrap 5.3 的新文件<br><a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.3/helpers/focus-ring/" target="_blank">https://getbootstrap.com/docs/5.3/helpers/focus-ring/</a></p>



<h2 class="wp-block-heading">總結</h2>



<p class="wp-block-paragraph">這次 Bootstrap 5.3 更新主要是在深色模式 Dark mode，還有各種色系、色票的更新，並沒有大的架構或排版上的更新。</p>



<p class="wp-block-paragraph">Dark mode 的確是近幾年的 CSS 主題：Windows / Mac / Android / iPhone / iPad 作業系統都支援 Dark mode，當然細緻一點的 web app，應該也要支援 Dark mode。</p>



<p class="wp-block-paragraph">調色盤色票的更新，則是讓我們再 review 一次，未來可不可用 Bootstrap 內建的色票架構。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Bootstrap 5.2 主要更新：幾乎全部元件都用 CSS 變數實作，新的 CSS build sequence</title>
		<link>https://blog.yuyansoftware.com.tw/2022/07/bootstrap-5-2-features/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Fri, 29 Jul 2022 03:36:00 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<guid isPermaLink="false">https://blog.yuyansoftware.com.tw/?p=11285</guid>

					<description><![CDATA[Bootstrap 5.2 沒有大的架構更新，就是多了一些 CSS helper class。CSS 變數的使用幾乎遍及所有元件，所以 CSS 變數的使用越來越重要。以及調整了 Bootstrap CSS build sequence。]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">圖片來源 <a href="https://blog.getbootstrap.com/2022/05/16/using-bootstrap-css-vars/" target="_blank" rel="noreferrer noopener nofollow">Bootstrap官方部落格</a></p>



<p class="wp-block-paragraph"><a href="https://blog.getbootstrap.com/2022/07/19/bootstrap-5-2-0/" target="_blank" rel="noreferrer noopener nofollow">https://blog.getbootstrap.com/2022/07/19/bootstrap-5-2-0/</a><br>前幾天 (2022/7/19) Bootstrap 5.2 發布了。每次看到 Bootstrap 新版本的發布，都會有感於時間過的真的很快。以下是我關於 Bootstrap 的文章，大致的時間線：</p>



<ul class="wp-block-list">
<li>2021年8月：<a href="https://blog.yuyansoftware.com.tw/2021/08/bootstrap-5-1-css-grid-custom-property/">Bootstrap 5.1 主要更新</a></li>



<li>2020年12月：<a href="https://blog.yuyansoftware.com.tw/2020/12/bootstrap-5-features/">Bootstrap 5 主要更新</a></li>



<li>2018年4月：<a href="https://blog.yuyansoftware.com.tw/2018/04/bootstrap-4-flex/">Bootstrap 4 Flex</a> (那時 Bootstrap 4.1 發布)</li>



<li>2017年8月：<a href="https://blog.yuyansoftware.com.tw/2017/08/bootstrap-4-beta/">Bootstrap 4 主要更新</a></li>
</ul>



<p class="wp-block-paragraph">撰文的現在是2022年7月。可以看到每一個 Bootstrap minor version 的更新，就是半年～1年。更甭論 major version 的更新是好幾年一版。所以每次寫 Bootstrap，就代表好多歲月又過去了。</p>



<p class="wp-block-paragraph">以下是 Bootstrap 5.2 的主要更新：</p>



<h2 class="wp-block-heading">官網首頁重新設計，以及文件網頁優化</h2>



<p class="wp-block-paragraph">重新設計了 Bootstrap 官網首頁，文件網頁也有多處優化，包含左側 menu 的重組，文件搜尋的使用體驗，等等。</p>



<h2 class="wp-block-heading">更新按鈕樣式</h2>



<p class="wp-block-paragraph">border-radius 調大了一點，雖然按鈕大小跟之前一樣，看起來好像 padding 變小而文字更突出的感覺。</p>



<h2 class="wp-block-heading">幾乎全部元件都用 CSS 變數 (custom property) 實作</h2>



<p class="wp-block-paragraph">比 Bootstrap 5.1 更多的 CSS 變數實作，幾乎全部元件都是。</p>



<h2 class="wp-block-heading">新的 _maps.scss</h2>



<p class="wp-block-paragraph">有一個新的 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">scss/_maps.scss</mark></code> (Bootstrap 5.1 沒有)。<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">_maps.scss</mark></code> 將一些 Sass map 從 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">_variables.scss</mark></code> 抽出。修正對原始 Sass map 修改時，基於原始 Sass map 擴展的 map，不會繼承這些修改的問題。</p>



<p class="wp-block-paragraph">舉例來說 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">$utilities-colors</mark></code> 基於 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">$theme-colors</mark></code> 擴展。因為 Bootstrap 5.1 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">$utilities-colors</mark></code> 在 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">_variables.scss</mark></code> 就定義生成了，所以在</p>



<pre class="wp-block-code"><code>@import "variables";</code></pre>



<p class="wp-block-paragraph">之後對 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">$theme-colors</mark></code> 的修改，都不會繼承到 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">$utilities-colors</mark></code> (它已經生成了)。</p>



<p class="wp-block-paragraph">而 Bootstrap 5.2 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">$utilities-colors</mark></code> 移到 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">_map.scss</mark></code>，整個架構上會比較清楚，你的 Bootstrap CSS build 順序可以參考：</p>



<pre class="wp-block-code"><code>// Functions come first
@import "functions";

// Your optional variable overrides here

// Variables come next
@import "variables";

// Your optional Sass map overrides here

// Third the default maps
@import "maps";

// The rest
@import "mixins";
@import "utilities";
@import "root";
@import "reboot";</code></pre>



<h2 class="wp-block-heading">新的 CSS helpers and utilities</h2>



<p class="wp-block-paragraph">新的 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.text-bg-{color}</mark></code> helper，使用 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.text-bg-{color}</mark></code> 可以直接設定 background-color 和文字顏色，而不是兩個 css class 個別設定。</p>



<p class="wp-block-paragraph">font-weight 方面新增 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.fw-semibold</mark></code> (font weight 600)。border-radius 方面新增 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.rounded-4</mark></code> (border radius 1rem) <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.rounded-5</mark></code> (border radius 2rem)</p>



<h2 class="wp-block-heading">Responsive offcanvas</h2>



<p class="wp-block-paragraph">Bootstrap 5.2 可以使用 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.offcanvas-{sm|md|lg|xl|xxl}</mark></code>，例如 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.offcanvas-lg</mark></code>，在 viewport 大於 lg breakpoint 時，已經顯示的 offcanvas 會隱藏。</p>



<p class="wp-block-paragraph">Bootstrap 5.0、5.1 就開始使用的 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.offcanvas</mark></code> class 仍然存在，使用 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.offcanvas</mark></code> 顯示就不隨 viewport 大小而改變。</p>



<h2 class="wp-block-heading">compile CSS Grid 版本時可以包含 container class</h2>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">scss/_variables.scss</mark></code> 新增了一個變數 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">$enable-container-classes</mark></code>，如果是 true，當 compile 成 CSS Grid 版本，container class 仍然會 compile 進去 (5.1 之前不會)。</p>



<h2 class="wp-block-heading">總結</h2>



<p class="wp-block-paragraph">Bootstrap 5.2 沒有大的架構更新，就是多了一些 CSS helper class。CSS 變數的使用幾乎遍及所有元件，所以大家要知道 CSS 變數的使用是一個趨勢。也要稍微知道一下新的 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">_maps.scss</mark></code>，它的邏輯是什麼，Bootstrap 5.2 CSS build 的順序是什麼。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Bootstrap 5.1 主要更新：開始使用 CSS Grid 實作 grid system，新的元件，更多的 CSS 變數 (custom property)</title>
		<link>https://blog.yuyansoftware.com.tw/2021/08/bootstrap-5-1-css-grid-custom-property/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Tue, 24 Aug 2021 07:46:34 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<guid isPermaLink="false">https://blog.yuyansoftware.com.tw/?p=8377</guid>

					<description><![CDATA[很多專家認為 CSS Grid 是繼 Flexbox 後，近代 CSS 的另一個里程碑。Bootstrap 4 開始使用 Flexbox 實作 grid system，Bootstrap 5.1 開始可以切換為 CSS Grid 實作。]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">圖片來源 <a href="https://blog.getbootstrap.com/2020/06/16/bootstrap-5-alpha/" target="_blank" rel="noreferrer noopener nofollow">Bootstrap官方部落格</a></p>



<p class="wp-block-paragraph"><a href="https://blog.getbootstrap.com/2021/08/04/bootstrap-5-1-0/" target="_blank" rel="noreferrer noopener nofollow">https://blog.getbootstrap.com/2021/08/04/bootstrap-5-1-0/</a><br>前幾天 (2021年 8/4) Bootstrap 5.1 釋出了。每次看到新的 Bootstrap 版本釋出，都會有感於時間過的真的飛快。</p>



<p class="wp-block-paragraph">上一篇我關於 Bootstrap 5 的<a href="https://blog.yuyansoftware.com.tw/2020/12/bootstrap-5-features/">文章</a>是在去年底 (2020年底)，一轉眼 2021 年大半年又過了。</p>



<p class="wp-block-paragraph">以下是 Bootstrap 5.1 的主要更新：</p>



<h2 class="wp-block-heading" id="使用-css-grid-實作-grid-system">使用 CSS Grid 實作 grid system</h2>



<p class="wp-block-paragraph">使用 CSS Grid 實作 grid system 是 <meta charset="utf-8">Bootstrap 5.1 的主要更新。很多專家認為 CSS Grid 是繼 Flexbox 後，近代 CSS 的另一個里程碑。Bootstrap 4 開始使用 Flexbox 實作 grid system，<meta charset="utf-8">Bootstrap 5.1 預設也是 Flexbox <meta charset="utf-8">實作，但可以切換為 CSS Grid 實作。</p>



<p class="wp-block-paragraph">同時也釋出了新的 CSS Grid 文件，5.0 還沒有這頁文件，從 5.1 開始。<br><a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.1/layout/css-grid/" target="_blank">https://getbootstrap.com/docs/5.1/layout/css-grid/</a></p>



<p class="wp-block-paragraph">Bootstrap 5.1 如何切換 Flexbox 實作到 CSS Grid 實作？找到檔案位置 <code><span class="has-inline-color has-vivid-cyan-blue-color">/bootstrap-5.1.0/scss/_variables.scss</span></code><span class="has-inline-color has-black-color">, 設定</span>這兩個變數</p>



<pre class="wp-block-code"><code>$enable-grid-classes: false; 
$enable-cssgrid: true;</code></pre>



<p class="wp-block-paragraph">改好了重新 compile SCSS。Bootstrap 5.0 的 <code><span class="has-inline-color has-vivid-cyan-blue-color">_variables.scss</span></code> 沒有 <code><span class="has-inline-color has-vivid-cyan-blue-color">$enable-cssgrid</span></code> <meta charset="utf-8">這個變數，所以可以確定是 5.1 引入的。</p>



<p class="wp-block-paragraph">一樣是 Bootstrap Grid System row/col 的架構，只是將 row 換成 grid，col 換成 g-col。例如這樣三個 div 分別在 12 份中佔有一份、兩份、和三份。<br><code><span class="has-inline-color has-vivid-cyan-blue-color">.grid</span></code> 設定 <code><span class="has-inline-color has-vivid-cyan-blue-color">display:grid</span></code>，<code><span class="has-inline-color has-vivid-cyan-blue-color">g-col-*</span></code> 設定 <code><span class="has-inline-color has-vivid-cyan-blue-color">grid-column</span></code></p>



<pre class="wp-block-code"><code>&lt;div class="grid"&gt;
  &lt;div class="g-col-1"&gt;
    Column
  &lt;/div&gt;
  &lt;div class="g-col-2"&gt;
    Column
  &lt;/div&gt;
  &lt;div class="g-col-3"&gt;
    Column
  &lt;/div&gt;
&lt;/div&gt;</code></pre>



<p class="wp-block-paragraph"><code><span class="has-inline-color has-vivid-cyan-blue-color">.grid</span></code> 同時定義了 CSS gap。相較於用 padding/margin 去做 gutter，gap 是新一代做 gutter 的方式。如果仔細去看，每個 g-col 本身沒有 padding/margin，但卻能彼此分開，這不符合 CSS box model 阿？larry 看到一種說法，gutter 如字面翻譯是水溝，在 CSS Grid 裡面 gutter 本身就是一種物件，會佔面積。而 gap 只是定義了 gutter 的寬度。</p>



<p class="wp-block-paragraph">下方是 Bootstrap CSS Grid 文件中的 sample code。這個 sample 做了一個 9&#215;9 的 grid，第一個 child 是第一行第一個，第二個 child 是第二行第二個，第三個 child 是第三行第三個。以賓果遊戲來說，是左上到右下連線的圖形。</p>



<pre class="wp-block-code"><code>&lt;div class="grid" style="--bs-rows: 3; --bs-columns: 3;"&gt;
  &lt;div&gt;Auto-column&lt;/div&gt;
  &lt;div class="g-start-2" style="grid-row: 2"&gt;Auto-column&lt;/div&gt;
  &lt;div class="g-start-3" style="grid-row: 3"&gt;Auto-column&lt;/div&gt;
&lt;/div&gt; </code></pre>



<p class="wp-block-paragraph">從這個 sample 我們可以看出</p>



<ol class="wp-block-list">
<li>Bootstrap 官方鼓勵 inline CSS custom property 的使用。inline 指定 <code><span class="has-inline-color has-vivid-cyan-blue-color">--bs-rows</span></code>, <code><span class="has-inline-color has-vivid-cyan-blue-color">--bs-columns</span></code> 是不是更靈活，redundant code 更少一些。</li>



<li><code><span class="has-inline-color has-vivid-cyan-blue-color">g-start-*</span></code> 可以指定水平開頭的位置，inline CSS <code><span class="has-inline-color has-vivid-cyan-blue-color">grid-row</span></code> 可以指定是屬於第幾行。</li>
</ol>



<h2 class="wp-block-heading" id="offcanvas-in-navbar-new-component">Offcanvas in navbar (new component)</h2>



<p class="wp-block-paragraph">Offcanvas 在 Bootstrap 5.0 已經新增了，是一個新的元件。觸發時左、右、上、下其中一側彈出視窗，按按鈕或按叉結束時再縮回原處。</p>



<p class="wp-block-paragraph">Bootstrap 5.1 將 Offcanvas 和 navbar 做整合。尤其手機版的 navbar 通常會縮成一個 toggle button，點了之後可以指定 Offcanvas 從哪個方向彈出，navbar 的內容可以放在 Offcanvas 裡面。</p>



<h2 class="wp-block-heading" id="placeholder-new-component">Placeholder (new component)</h2>



<p class="wp-block-paragraph">將還沒 load 好的文字，用銀色區塊替代。例如 Facebook，早就是這樣做 placeholder。</p>



<p class="wp-block-paragraph">在要顯示銀色區塊的 DOM (不一定是銀色，可以自行設定 <code><span class="has-inline-color has-vivid-cyan-blue-color">background-color</span></code>)，加上 CSS class <code><span class="has-inline-color has-vivid-cyan-blue-color">.placeholder</span></code>，DOM 的寬度要設定一下。container 可以加上 CSS class <code><span class="has-inline-color has-vivid-cyan-blue-color">.placeholder-glow</span></code> 或 <code><span class="has-inline-color has-vivid-cyan-blue-color">.placeholder-wave</span></code>，讓 placeholder 區塊有小小的水波閃爍。</p>



<h2 class="wp-block-heading" id="bg-text-utility-的實作變數化">.bg-* &amp; .text-* utility 的實作變數化</h2>



<p class="wp-block-paragraph">Bootstrap 5.0 中 background color utility 實作如下 (text color utility 類似，僅用 background 舉例)</p>



<pre class="wp-block-code"><code>.bg-success {
  background-color: #198754 !important;
}</code></pre>



<p class="wp-block-paragraph">Bootstrap 5.1 改為</p>



<pre class="wp-block-code"><code>.bg-success {
  --bs-bg-opacity: 1;
  background-color: rgba(var(--bs-success-rgb), var(--bs-bg-opacity)) !important;
}</code></pre>



<p class="wp-block-paragraph">這樣如果你要微調 <code><span class="has-inline-color has-vivid-cyan-blue-color">.bg-success</span></code> 的顏色，在你的專案裡重新設定 <code><span class="has-inline-color has-vivid-cyan-blue-color">--bs-success-rgb</span></code> 就好了。未來 Bootstrap 會接著把其他 utility 也變數化。Bootstrap 的演進<meta charset="utf-8">有這樣的味道：<meta charset="utf-8">Bootstrap 只管架構，顏色等屬性由 CSS 變數設定。對軟體工程有研究的讀者應該知道，資料 / 邏輯分離的概念。</p>



<h2 class="wp-block-heading" id="結論">總結</h2>



<p class="wp-block-paragraph">Bootstrap 5.1 開始使用 CSS Grid 實作 grid system，而且又新增了很多元件。從 Bootstrap 的發展和文件可以看出來，Bootstrap 非常大量的使用 CSS custom property，同時也鼓勵開發者在專案裡使用 CSS custom property 做出變化。CSS Grid、Bootstrap 的新元件、CSS custom property 的使用，都是很值得參考的。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Bootstrap 5 主要更新：不再相依 jQuery，新增 Utilities API，使用 CSS custom properties</title>
		<link>https://blog.yuyansoftware.com.tw/2020/12/bootstrap-5-features/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Fri, 11 Dec 2020 11:44:54 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<guid isPermaLink="false">https://blog.yuyansoftware.com.tw/?p=5820</guid>

					<description><![CDATA[本篇會走一遍 Bootstrap 5 的主要更新，懂前端工程的讀者，可以看看有沒有東西是值得拿來使用，或進一步再去研讀的。以下大致是從 Bootstrap 5 比較重要的部分，往比較 minor 的部分排序。]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">圖片來源 <a href="https://blog.getbootstrap.com/2020/06/16/bootstrap-5-alpha/" target="_blank" rel="noreferrer noopener nofollow">Bootstrap官方部落格</a></p>



<p class="wp-block-paragraph"><a href="https://blog.getbootstrap.com/2020/12/07/bootstrap-5-beta-1/" target="_blank" rel="noreferrer noopener nofollow">https://blog.getbootstrap.com/2020/12/07/bootstrap-5-beta-1/</a><br>Bootstrap 5 beta 幾天前發佈了，時間過得真的很快，Bootstrap 4 beta 發佈時 (2017 年 8 月) 我有一篇文章 <a href="https://blog.yuyansoftware.com.tw/2017/08/bootstrap-4-beta/">Bootstrap 4 主要更新：Grid System、CSS</a></p>



<p class="wp-block-paragraph">2018 年我還有一篇關於 Bootstrap 4 Flexbox 的文章 <a href="https://blog.yuyansoftware.com.tw/2018/04/bootstrap-4-flex/">Bootstrap 4 Flex</a></p>



<p class="wp-block-paragraph">本篇會走一遍 Bootstrap 5 的主要更新，懂前端工程的讀者，可以看看有沒有東西是值得拿來使用，或進一步再去研讀的。以下大致是從 Bootstrap 5 比較重要的部分，往比較 minor 的部分排序。</p>



<h2 class="wp-block-heading" id="移除-jquery-的相依性">移除 jQuery 的相依性</h2>



<p class="wp-block-paragraph">移除對 library 的相依性就軟體工程來說本來就是好的，開發者也不用在引入 Bootstrap 前先引入 jQuery，可能還會有版本相容的問題。以整個專案來說，應該也會更輕量，而且因為使用原生的 JavaScript，效能應該也應該會更好。</p>



<h2 class="wp-block-heading" id="utilities-api-with-the-state-option">Utilities API (with the state option)</h2>



<p class="wp-block-paragraph"><a href="https://getbootstrap.com/docs/5.0/utilities/api/" target="_blank" rel="noreferrer noopener">https://getbootstrap.com/docs/5.0/utilities/api/</a><br>Utilities API 是基於 Sass maps 的技術，可以先看一下 Sass maps 的官方文件<br><a href="https://sass-lang.com/documentation/values/maps" target="_blank" rel="noreferrer noopener">https://sass-lang.com/documentation/values/maps</a></p>



<p class="wp-block-paragraph">基本上 Sass maps 就是一連串的 key / value pairs，用小括號括起來。調用端可以用 <code><span style="color:#505050" class="has-inline-color">map.get</span></code> function 去把指定變數裡的指定的 key 的值讀取出來，詳細寫法跟變化可以參考上方 Sass maps 的官方文件。使用 Sass maps 可以把 CSS 的設定組織化。</p>



<p class="wp-block-paragraph">Bootstrap 5 基於 Sass maps 的架構衍伸出一套讓開發者可以自行設定 utility classes，就是 Utilities API，而且 Bootstrap 5 預設的 utility classes 也是用 Utilities API 實作的。這次 beta release 特別提到 Utilities API 加入了 <code><span style="color:#515151" class="has-inline-color">state</span></code> option，可以指定 pseudo-class 像是 hover、focus 等。</p>



<p class="wp-block-paragraph">Utilities API 的主要功能在產生同樣屬性，不同數值的 utility classes。larry 覺得 Sass maps 和 Bootstrap 5 Utilities API 都是滿值得參考的。</p>



<h2 class="wp-block-heading" id="使用-css-custom-properties-實作底層-css">使用 CSS custom properties 實作底層 CSS</h2>



<p class="wp-block-paragraph">CSS custom properties 讓原生 CSS 可以支援變數，而不需要 Sass 或其他語言來協助。變數要以 &#8211; &#8211; (double dash) 開頭，用 <mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color"><code>var</code></mark> function 讀取，例如</p>



<pre class="wp-block-code"><code>--my-text-color: #554433;
color: var(--my-text-color);</code></pre>



<p class="wp-block-paragraph">如果要切換樣式，可以這樣寫</p>



<pre class="wp-block-code"><code>.my-text-style1 {
  --my-text-color: #554433;
}
.my-text-style2 {
  --my-text-color: #998877;
}
...
color: var(--my-text-color); // 這一行不用動</code></pre>



<p class="wp-block-paragraph">而不是</p>



<pre class="wp-block-code"><code>.my-text-style1 {
  color: #554433;
}
.my-text-style2 {
  color: #998877;
}</code></pre>



<p class="wp-block-paragraph">所以同一架構不同樣式，就下不同的 CSS 變數就好，而不是重寫 CSS，這樣管理或擴充樣式的話都會容易而且輕量很多。實際 Bootstrap 5 底層是怎麼使用，有興趣的讀者可以再去研究看看。</p>



<h2 class="wp-block-heading" id="rtl-right-to-left-text-右到左排序的文字">RTL (right-to-left text) 右到左排序的文字</h2>



<p class="wp-block-paragraph"><a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.0/getting-started/rtl/" target="_blank">https://getbootstrap.com/docs/5.0/getting-started/rtl/</a><br>就是橫式的文字由右到左排序 (一般我們習慣網頁文字是由左到右排序)。要使用 RTL，要先在 &lt;html&gt; 上設定 dir=&#8221;rtl&#8221; 還有 lang 兩個屬性。詳細的寫法參考上方官方文件。</p>



<h2 class="wp-block-heading" id="重新命名某些-css-class-用-start-end-取代-left-right">重新命名某些 CSS Class，用 start / end 取代 left / right</h2>



<p class="wp-block-paragraph">為了支援 RTL，帶有 left / right 意涵的 CSS class，例如 ml-3 代表 margin-left，將會用 start / end 的邏輯來取代。這樣當換文字方向時，不用整篇 css 重改一遍。例如在 Bootstrap 5 請使用 ms-3 (s means start) 代替 ml-3，在 LTR (左到右) 文本時，ms-3 是 margin-left，但在 RTL (右到左) 文本時，ms-3 是 margin-right。</p>



<h2 class="wp-block-heading" id="加強了-grid-system">加強了 Grid System</h2>



<p class="wp-block-paragraph">新增 xxl 的 breakpoint，gutter class (cell 間距) 的設定，等等。</p>



<h2 class="wp-block-heading" id="新樣式的輸入框-選擇按鈕">新樣式的輸入框，選擇按鈕</h2>



<p class="wp-block-paragraph">包含 <a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.0/forms/floating-labels/" target="_blank">Floating labels</a>，<a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.0/forms/form-control/#file-input" target="_blank">New file input</a>，checkbox，radio buttons，switch buttons 等等。</p>



<h2 class="wp-block-heading" id="全新的-customize-文件網頁">全新的 Customize 文件網頁</h2>



<p class="wp-block-paragraph"><a rel="noreferrer noopener" href="https://getbootstrap.com/docs/5.0/customize/overview/" target="_blank">https://getbootstrap.com/docs/5.0/customize/overview/</a><br>如果要客製化設定一些 CSS，請參考這些 coding convention。</p>



<h2 class="wp-block-heading" id="升級-popper-js-到-v2">升級 Popper.js 到 v2</h2>



<p class="wp-block-paragraph">Popper.js 就是一些 tooltip / popup 的效果。</p>



<h2 class="wp-block-heading" id="使用-data-bs-attribute-取代原本的-data-attribute">使用 data-bs-attribute 取代原本的 data-attribute </h2>



<p class="wp-block-paragraph">例如本來的 data-toggle=&#8221;dropdown&#8221;，現在是 data-bs-toggle=&#8221;dropdown&#8221;。加 bs 可以讓開發者更好辨認出這是 Bootstrap 的屬性。</p>



<h2 class="wp-block-heading" id="用純-css-的方法來指定-toast-的位置">用純 CSS 的方法來指定 Toast 的位置</h2>



<p class="wp-block-paragraph">在 Bootstrap，Toast 指的就是小的通知方塊，也許是服務提供方的來訊，也許是其他用戶的來訊。開發者可以使用純 CSS 的方法來指定 Toast 的位置。</p>



<h2 class="wp-block-heading" id="結論">總結</h2>



<p class="wp-block-paragraph">以上是 Bootstrap 5 的主要更新，Utilities API，CSS custom properties，新的 Grid System，新的 Customize 文件，這些都是 larry 覺得滿有參考價值的部分。</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Bootstrap 4 Flex</title>
		<link>https://blog.yuyansoftware.com.tw/2018/04/bootstrap-4-flex/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Thu, 19 Apr 2018 08:25:00 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Flex 是 CSS3 很重要的一種佈局方式，Bootstrap 4 也出了很多 help class, 建議對前端有興趣的朋友要使用。有很多排列組合，尤其是對齊方面，但不用糾結在其中，一切還是以設計和實務需求來做驅動。]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">圖片來源 <a href="https://laravel-news.com/bootstrap-4-laravel-preset" target="_blank" rel="noreferrer noopener nofollow">Laravel官方部落格</a></p>



<p class="wp-block-paragraph"><a href="http://blog.getbootstrap.com/2018/04/09/bootstrap-4-1" target="_blank" rel="noreferrer noopener nofollow">http://blog.getbootstrap.com/2018/04/09/bootstrap-4-1</a><br>Bootstrap 4.1 前幾天釋出了，主要只是新增一些 class 可供使用，沒什麼 major change. larry 只有注意到一點：Added new <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.flex-fill</mark></code>, <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.flex-grow-*</mark></code>, and <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">.flex-shrink-*</mark></code> utilities.</p>



<p class="wp-block-paragraph">我想趁這個機會從頭看一遍 Bootstrap flex utility<br><a href="https://getbootstrap.com/docs/4.1/utilities/flex" target="_blank" rel="noreferrer noopener nofollow">https://getbootstrap.com/docs/4.1/utilities/flex</a></p>



<p class="wp-block-paragraph">如 native css 一樣，要使用 flexbox, 要在 container 上宣告&nbsp;<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex"</mark></code> 或是&nbsp;<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-inline-flex"</mark></code> (可以看出來 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">d-inline-flex</mark></code> 是行內元素)</p>



<p class="wp-block-paragraph">接著你可以指定 flexbox 裡面 children 排列的方向，例如：</p>



<ul class="wp-block-list">
<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex flex-row"</mark></code> (橫排，左到右，這是預設值，一般不用加 flex-row)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex flex-row-reverse"</mark></code> (橫排，右到左)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex flex-column"</mark></code> (直排，上到下)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex flex-column-reverse"</mark></code> (直排，下到上)</li>
</ul>



<p class="wp-block-paragraph">這邊 flex-row, flex-column 對應的是 css 的&nbsp;flex-direction</p>



<p class="wp-block-paragraph">justify-content 指定左右方向如何分佈</p>



<ul class="wp-block-list">
<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex justify-content-start"</mark></code> (從左到右，這是預設值，一般不用加 justify-content-start)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex justify-content-end"</mark></code> (從右到左)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex justify-content-center"</mark></code> (置中)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex justify-content-between"</mark></code> (平均分配間距)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex justify-content-around"</mark></code> (平均分配間距，且分配的間距再分配到單一 child 的左右)</li>
</ul>



<p class="wp-block-paragraph">align-items 指定垂直方向如何分佈</p>



<ul class="wp-block-list">
<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex align-items-start"</mark></code> (從上到下，這是預設值，一般不用加 justify-content-start)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex align-items-end"</mark></code> (從下到上)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex align-items-center"</mark></code> (垂直置中)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex align-items-baseline"</mark></code> (這比較特殊，不常用，有興趣的朋友請自行 study)</li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="d-flex align-items-stretch"</mark></code> (所有 children 垂直方向佔滿 container)</li>
</ul>



<p class="wp-block-paragraph">到這邊大家會不會想到一個問題，如果 flex-column 搭配 align-items-center 會如何？(以下使用 native css 測試，如果 Bootstrap 的 css class 結果不一樣請讓我知道 <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-direction: column</mark></code> 搭配 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">align-items: center</mark></code>，3個 children 依然由上往下，但會水平置中</p>



<div style="align-items: center; border: 1px solid #777; display: flex; flex-direction: column; height: 200px;">
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 1</div>
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 2</div>
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 3</div>
</div>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-direction: column</mark></code> 搭配 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">justify-content: center</mark></code>，3個 children 會垂直置中</p>



<div style="border: 1px solid #777; display: flex; flex-direction: column; height: 200px; justify-content: center;">
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 1</div>
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 2</div>
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 3</div>
</div>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-direction: column</mark></code> 搭配 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">justify-content: flex-end</mark></code>，3個 children 會向下對齊</p>



<div style="border: 1px solid #777; display: flex; flex-direction: column; height: 200px; justify-content: flex-end;">
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 1</div>
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 2</div>
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 3</div>
</div>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-direction: column</mark></code> 搭配 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">justify-content: center</mark></code> 且 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">align-items: center</mark></code>，3個 children 會水平且垂直置中</p>



<div style="align-items: center; border: 1px solid #777; display: flex; flex-direction: column; height: 200px; justify-content: center;">
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 1</div>
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 2</div>
<div style="border: 1px solid #555; width: 100px; padding:5px;">Child 3</div>
</div>



<p class="wp-block-paragraph">大家有發現嗎？justify-content 是管水平方向對齊的，align-items 是管垂直方向對齊的。但當 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-direction: column</mark></code> 時，justify-content 與 align-items 管的方向顛倒了。</p>



<p class="wp-block-paragraph">align-self 下在 child 身上，可以指定單一 child 的對齊方式</p>



<ul class="wp-block-list">
<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="align-self-start"</mark></code></li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="align-self-end"</mark></code></li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="align-self-center"</mark></code></li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="align-self-baseline"</mark></code></li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="align-self-stretch"</mark></code></li>
</ul>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-fill</mark></code> 是 Bootstrap 4.1 新的 css class，下在 child 身上，就是 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex:1</mark></code>，等分占滿的意思。</p>



<p class="wp-block-paragraph"><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-grow-*</mark></code>，<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-shrink-*</mark></code> (* 只能是 0 或 1) 也是 Bootstrap 4.1 新的 css class，下在 child 身上，對應 native css 的 flex-grow，flex-shrink。</p>



<p class="wp-block-paragraph">官方文件有提到，justify-content，align-items 與 margin-(top)(bottom)(left)(right): auto 組合會有很多不同的排列效果。</p>



<p class="wp-block-paragraph">flex-wrap 的部分有 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-nowrap</mark></code>，<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-wrap</mark></code>，<code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">flex-wrap-reverse</mark></code>。下在 container 身上，管理 children 是否換行。</p>



<p class="wp-block-paragraph">children 可以下 <code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">order-*</mark></code> (* 可以是 1 ~ 12)，指定 children 的排列順序。</p>



<p class="wp-block-paragraph">align-content 操縱的是 children 的對齊線，跟&nbsp;align-items 不同的是&nbsp;align-items 以 children 為單位去做對齊，而 align-content 操縱的是行線。</p>



<ul class="wp-block-list">
<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="align-content-start"</mark></code></li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="align-content-end"</mark></code></li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="align-content-center"</mark></code></li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="align-content-around"</mark></code></li>



<li><code><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-cyan-blue-color">class="align-content-stretch"</mark></code></li>
</ul>



<p class="wp-block-paragraph">以上就是 Bootstrap 4.1 flex utility 所有內容。簡短結論一下吧，flexbox 是好東西，建議對前端有興趣的讀者使用。有很多排列組合，尤其是對齊方面，不要糾結他們，或是死背什麼，一切還是以設計和真實的需求為主～</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Bootstrap 4 主要更新：Grid System、CSS</title>
		<link>https://blog.yuyansoftware.com.tw/2017/08/bootstrap-4-beta/</link>
		
		<dc:creator><![CDATA[Larry]]></dc:creator>
		<pubDate>Thu, 17 Aug 2017 08:58:00 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[Bootstrap]]></category>
		<guid isPermaLink="false">http://test234.yuyansoftware.com.tw/2017/08/17/bootstrap-4-beta-released/</guid>

					<description><![CDATA[Bootstrap 4 beta 在日前發佈了，本篇文章記錄了 v4 的主要的更動。如果是同為開發者的朋友，可以想想為什麼 bootstrap v4 要採納這些更動，有什麼技術是值得我們進一步去研讀的。]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">圖片來源 <a href="https://laravel-news.com/bootstrap-4-laravel-preset" target="_blank" rel="noreferrer noopener nofollow">Laravel官方部落格</a></p>



<p class="wp-block-paragraph"><a href="https://blog.getbootstrap.com/2017/08/10/bootstrap-4-beta/" target="_blank" rel="noreferrer noopener nofollow">https://blog.getbootstrap.com/2017/08/10/bootstrap-4-beta/</a><br>Bootstrap 4 beta 在日前發佈了，以下是 v4 的主要更新。如果是同為開發者的朋友，可以想想為什麼 Bootstrap 4 要採納這些更動，有什麼技術是值得我們進一步去研讀的。</p>



<h2 class="wp-block-heading">Moved from Less to Sass</h2>



<p class="wp-block-paragraph">前端的朋友應該知道，bootstrap 3.x 版是用 <a rel="noreferrer noopener" aria-label=" (在新分頁中開啟)" href="http://lesscss.org/" target="_blank">less</a>, css相關檔案也都是 .less 檔. Bootstrap v4 開始用 <a href="http://sass-lang.com/" target="_blank" rel="noreferrer noopener" aria-label=" (在新分頁中開啟)">Sass</a> (正確來說應該是 Scss), css相關檔案變成是 .scss 檔。</p>



<h2 class="wp-block-heading">Flexbox and an improved grid system</h2>



<p class="wp-block-paragraph">官方文件提到</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">&#8220;We&#39;ve moved nearly everything to flexbox.&#8221;</p>
</blockquote>



<p class="wp-block-paragraph">Bootstrap v4 幾乎所有排版都是用 css flexbox 的方式。另外，新增一個 grid system 的範圍: xl. 寫法上也要注意，3.x 版是</p>



<pre class="wp-block-code"><code>.col-xs- &nbsp;.col-sm- &nbsp;.col-md- &nbsp;.col-lg-</code></pre>



<p class="wp-block-paragraph">v4 是</p>



<pre class="wp-block-code"><code>.col &nbsp;.col-sm- &nbsp;.col-md- &nbsp;.col-lg- &nbsp;.col-xl-</code></pre>



<p class="wp-block-paragraph">注意 xs 不用再寫了，多了 xl。3.x 版是 3 個 breakpoint，v4 是 4 個 breakpoint。</p>



<h2 class="wp-block-heading">Dropped wells, thumbnails, and panels for cards.</h2>



<p class="wp-block-paragraph">拿掉 3.x 版的 wells, thumbnails. 新增 class=&#8221;card&#8221;, 以符合市面上極為大量的卡牌系統網頁。</p>



<h2 class="wp-block-heading">Forked Normalize.css and consolidated all our HTML resets into a new CSS module, Reboot.</h2>



<p class="wp-block-paragraph">作者有給原因 <a rel="noopener noreferrer" href="https://github.com/twbs/bootstrap/issues/21740" target="_blank">https://github.com/twbs/bootstrap/issues/21740</a><br>v4 reset browser 的工作現在會放在一支 _reboot.scss 裡。</p>



<h2 class="wp-block-heading">Brand new customization options</h2>



<p class="wp-block-paragraph">3.x 版做 customize 通常是再加 css 檔案。v4 開始官網建議直接去改 Sass 變數，然後重新 compile.</p>



<h2 class="wp-block-heading">Dropped IE8 and IE9 support, dropped older browser versions, and moved to rem units for component sizing.</h2>



<p class="wp-block-paragraph">可以簡單看一下 v4 grid 裡的 padding, font size, 全改為 rem 了。</p>



<h2 class="wp-block-heading">總結</h2>



<p class="wp-block-paragraph">以上是 Bootstrap 4 的主要更新，如果是同為開發者的朋友，可以想想為什麼 Bootstrap 4 要採納這些更動，有什麼技術是值得進一步去研讀的。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
