<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sandy on Medium]]></title>
        <description><![CDATA[Stories by Sandy on Medium]]></description>
        <link>https://medium.com/@ai6ejxu4?source=rss-5ddd7d611b0c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hICZWsZk3-9IIm7mrPIdQw.jpeg</url>
            <title>Stories by Sandy on Medium</title>
            <link>https://medium.com/@ai6ejxu4?source=rss-5ddd7d611b0c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 23:23:42 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ai6ejxu4/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[如何用CSS繪製三角形]]></title>
            <link>https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/%E5%A6%82%E4%BD%95%E7%94%A8css%E7%B9%AA%E8%A3%BD%E4%B8%89%E8%A7%92%E5%BD%A2-71478539fb1b?source=rss-5ddd7d611b0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/71478539fb1b</guid>
            <category><![CDATA[triangle]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[position]]></category>
            <category><![CDATA[borders]]></category>
            <dc:creator><![CDATA[Sandy]]></dc:creator>
            <pubDate>Thu, 03 Jan 2019 10:31:48 GMT</pubDate>
            <atom:updated>2019-01-03T10:31:48.069Z</atom:updated>
            <content:encoded><![CDATA[<p>實測如何用 css 的 border 屬性繪製出三角形</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KuhOWrBhlUrDAKM5i01XyQ.jpeg" /></figure><p>今天要來實測用 css 的 border (邊框) 屬性繪製出向量的三角形圖案。</p><p>說到 border 屬性，就想到是矩形的邊框，我們先繪製一個長寬皆為50px、邊框粗細為 3px 的正方形，並將四邊分別以不同的顏色設定看看效果：</p><pre>.t01 {<br>  width: 50px;<br>  height: 50px;<br>  border: 3px solid;<br>  border-color: #0099e5 #ff4c4c #34bf49 #fbb034;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/156/1*PcoHa0pBlG5l7me-wbyvww.png" /></figure><p>接下來增加 border 的值為 25px，可以清楚看到四個邊接合的地方其實是斜角，也就是每一個方向的邊其實是梯形，而不是長方形。</p><pre>.t02 {<br>  width: 50px;<br>  height: 50px;<br>  border: 25px solid;<br>  border-color: #0099e5 #ff4c4c #34bf49 #fbb034;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*PQf8P0AbHPnfjz4yc_zR2A.png" /></figure><p>那麼試想一下，假如將中間空白的區域( 長寬各為 50px )拿掉的話，這張圖會變成怎麼樣？我們將 width 和 height 的值改為 0 看看結果：</p><pre>.t03 {<br>  width: 0;<br>  height: 0;<br>  border: 25px solid;<br>  border-color: #0099e5 #ff4c4c #34bf49 #fbb034;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/140/1*5relALDJ3hfvrB5VxNYQcQ.png" /></figure><p>果然，和預想中的一樣，變成一個由四個三角形組成的正方形了。</p><p>所以假如我們需要用到一個箭頭向右邊的三角形，只需要把上、右、下三邊的 border 顏色設定為 transparent (透明)，就可以了：</p><pre>.t04 {<br>  width: 0;<br>  height: 0;<br>  border: 25px solid;<br>  border-color: transparent transparent transparent #fbb034;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/106/1*kPRkUH9XWC-2_VmvyzInWw.png" /><figcaption>只剩左邊有設定顏色，變成一個向右的箭頭</figcaption></figure><p>這個可以拿來做按鈕上的icon，我們試試看以虛擬元素將繪製的三角形加入至按鈕後面：</p><pre>.btn-more {<br>  background-color: #7d3f98;<br>  color: #fff;<br>  display: block;<br>  padding: 8px 25px;<br>  width: 60px;<br>  text-align: center;<br>  text-decoration: none;<br>  border-radius: 30px;<br>  font-size: 16px;<br>  position: relative;<br>}</pre><pre>.btn-more:hover,<br>.btn-more:active,<br>.btn-more:focus {<br>  background-color: #511378;<br>}</pre><pre>.btn-more:after {<br>  content:””;<br>  width: 0;<br>  height: 0;<br>  border-style: solid;<br>  border-width: 6px 0 6px 12px;<br>  border-color: transparent transparent transparent #fff;<br>  position: absolute;<br>  right: 15%;<br>  top: calc( 50% — 6px );<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*BL99tHo0HZ6qNOOBFVw1_w.png" /><figcaption>在按鈕後面以虛擬元素加入向右的三角形</figcaption></figure><p>想控制三角形的長寬的話，只要改變四個邊框的粗細( border-width分別設定)就可以了。這邊提供一個可以 Demo 繪製出來三角形的網站作為參考，若要繪製比較複雜的三角形時可以直接使用這個：<a href="http://apps.eky.hk/css-triangle-generator/zh-hant">CSS三角形產生器</a></p><p>最後我們再來做一個繪製三角形的應用，試試看繪製一個對話氣泡框的效果，把一個向下的三角形以虛擬元素的方式加在圓角矩形的後面：</p><pre>.dialog {<br>  color: #444;<br>  display: block;<br>  background-color: #ecf5ff;<br>  border: 2px solid;<br>  border-color: #c4e1ff;<br>  border-radius: 10px;<br>  width: 180px;<br>  line-height: 60px;<br>  position: relative;<br>  text-align:center;<br>}</pre><pre>.dialog:before,<br>.dialog:after {<br>  border: solid transparent;<br>  content: “”;<br>  width: 0;<br>  height: 0;<br>  position: absolute;<br>}</pre><pre>.dialog:after {<br>  border-width: 10px 10px 0 10px;<br>  border-top-color: #ecf5ff; /*淺色*/<br>  top: 60px;<br>  right: 20px;<br>}</pre><pre>.dialog:before {<br>  border-width: 13px 13px 0 13px;<br>  border-top-color: #c4e1ff; /*深色*/<br>  position: absolute;<br>  top: 60px;<br>  right: 17px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/1*V80xY64wPmOyuTDNfrvNgg.png" /><figcaption>繪製出有邊線的對話氣泡框</figcaption></figure><p>這邊要特別注意的是，底下的三角形，因為要繪製出有邊線的效果，其實是以兩個大小不同的三角形(淺色較小在上層、深色較大在下層)重疊起來所做出的效果，所以虛擬元素需要加入兩個( :before 和 :after )</p><pre>※ 註：虛擬元素 :after 在 :before 的上層，也可以設定 z-index 來指定上下層關係</pre><p>最後附上此次練習的原始碼：<a href="https://codepen.io/lin-hsienli/pen/PXQYzp">→ 點擊查看CodePen</a></p><p>此外，用 CSS 的 clip-path 這個屬性可以繪製出更多不同的幾何圖形，有興趣的話可以先試試看這個網站：<a href="http://bennettfeely.com/clippy/">Clippy — CSS clip-path maker</a></p><pre>※ IE、Edge 不支援 clip-path</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x4M2M-zH0JhjPoEnmzELmA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RJPYiY7pMict2Li4QTLUYg.png" /><figcaption>除了多邊形，還能利用 polygon(連續線段) 的差集特性做出中間有挖空的形狀路徑</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71478539fb1b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/%E5%A6%82%E4%BD%95%E7%94%A8css%E7%B9%AA%E8%A3%BD%E4%B8%89%E8%A7%92%E5%BD%A2-71478539fb1b">如何用CSS繪製三角形</a> was originally published in <a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A">UI/UX練功坊</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS選擇器介紹( 3)]]></title>
            <link>https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/css%E9%81%B8%E6%93%87%E5%99%A8%E4%BB%8B%E7%B4%B9-3-c35ce1e867d4?source=rss-5ddd7d611b0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/c35ce1e867d4</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[selectors]]></category>
            <category><![CDATA[css3]]></category>
            <dc:creator><![CDATA[Sandy]]></dc:creator>
            <pubDate>Wed, 19 Dec 2018 10:55:10 GMT</pubDate>
            <atom:updated>2018-12-20T06:18:14.632Z</atom:updated>
            <content:encoded><![CDATA[<p>css虛擬類別介紹</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErJQy-OeBSXKAxPJHR26dw.jpeg" /></figure><blockquote><strong>選取子元素的「child」型虛擬類別</strong></blockquote><p>這些虛擬類別，可以選擇同一階層所有的<strong>「子元素」</strong>中符合條件者：</p><p>E:first-child (選取第一個子元素 E )</p><p>E:last-child (選取最後一個子元素 E )</p><p>E:nth-child(n) (選取第 n 個子元素 E )</p><p>E:nth-child(odd) (選取第奇數個子元素 E，第 1、3、5、7…個)</p><p>E:nth-child(even) (選取第偶數個子元素 E，第 2、4、6、8…個)</p><p>E:nth-last-child(n) (選取倒數第 n 個子元素 E )</p><p>E:only-child (選取唯一的子元素 E )</p><pre>※ 注意：這邊的E寫的是子元素本身的標籤(子元素可以省略不寫，但虛擬類別與父元素之間要有半形空格)，若不指定元素標籤的話，就會不區分元素類型只依順序計算。</pre><p>實作範例如下：</p><pre>ul li:first-child {<br>  color: #f00;<br>}</pre><pre>ul li:last-child {<br>  color: #00f;<br>}</pre><pre>ul li:nth-child(3) {<br>  color: #0f0;<br>}</pre><pre>ul li:nth-last-child(3) {<br>  color: #f0f;<br>}</pre><pre>.my-table :nth-child(odd) td {<br>  background-color: #ccc;<br>}</pre><pre>.my-table :nth-child(even) td {<br>  background-color: #ffffce;<br>}</pre><pre>.my-table p:only-child {<br>  color: #f00;<br>}</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/maORML?editors=1100">查看範例:虛擬類別測試1、2</a></p><p>比較值得注意的是，可以將 :nth-child(n) 中的 n 寫成算式，這樣就能進行較複雜的選取了。<br>例如寫成 (3n) 就是選取 3 的倍數，第 3、6、9…個。進階一點寫成 (3n+2) 就是從第二個元素開始數，每三個子元素，因為這個算式會帶入 (3x0+2)、(3x1+2)、(3x2+2)，就是第 2、5、8…個子元素。<br>若將算式設為 (2n) 結果就與設定為 (even) 一樣，都是選取到偶數個；若設為 (2n+1) 就與設定為 (odd) 一樣，會選取到奇數個。</p><pre>.my-list2 :nth-child(3n) {<br>  color: #00f;<br>}</pre><pre>.my-list2 :nth-child(3n+2) {<br>  color: #f00;<br>}</pre><pre>.my-list3 :nth-child(2n) {<br>  color: #f00;<br>}</pre><pre>.my-list3 :nth-child(2n+1) {<br>  color: #00f;<br>}</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/maORML?editors=1100">查看範例:虛擬類別測試3、4</a></p><blockquote><strong>選取兄弟元素的「of-type」型虛擬類別</strong></blockquote><p>這些虛擬類別，可以選擇同一階層且<strong>「同一類元素」</strong>中符合條件者：</p><p>E:first-of-type (選取每個類別的第一個元素 E )</p><p>E:last-of-type (選取每個類別的最後一個元素 E )</p><p>E:nth-of-type(n) (選取每個類別的第 n 個元素 E )</p><p>E:nth-last-of-type(n) (選取每個類別的倒數第 n 個元素 E )</p><p>E:only-of-type (選取唯一的類別元素 E )</p><pre>※ 注意：這邊E寫的是要選取的元素標籤，若省略的話(即不指定元素類別)每種類別都會被選取到，可以依需求選到複合的類別。</pre><p>實作範例如下：</p><pre>&lt;html&gt;<br>&lt;head&gt;<br>  .wrap :first-of-type {<br>    color:#f00;<br>  }<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;div class=&quot;wrap&quot;&gt;<br>    &lt;h1&gt;我是h1元素&lt;/h1&gt;<br>    &lt;p&gt;我是第1個段落元素&lt;/p&gt;<br>    &lt;h3&gt;我是h3元素&lt;/h3&gt;<br>    &lt;p&gt;我是第2個段落元素&lt;/p&gt;<br>    &lt;h3&gt;我是第2個h3元素&lt;/h3&gt;<br>    &lt;p&gt;我是第3個段落元素&lt;/p&gt;<br>    &lt;h3&gt;我是第3個h3元素&lt;/h3&gt;<br>    &lt;p&gt;我是第4個段落元素&lt;/p&gt;<br>    &lt;h5&gt;我是h5元素&lt;/h5&gt;<br>    &lt;p&gt;我是第5個段落元素&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>以這個範例來說 :first-of-type 因為沒有指定要哪一個類別，所以每一個類別的第一個元素都會被選取，也就是 h1、p、h3、h5 這四種元素的第一個元素都會變成紅色文字。</p><p>→ <a href="https://codepen.io/lin-hsienli/pen/wRodeq">查看Demo(範例1)</a></p><p>另外，我們再寫一個 :only-of-type 試試看，因為這個範例中只有 h1 和 h5 元素只有一個，其他元素都是不只一個，所以只有 h1 和 h5 變成藍色文字。</p><pre>&lt;html&gt;<br>&lt;head&gt;<br>  .wrap2 :only-of-type {<br>    color: #00f;<br>  }<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;div class=&quot;wrap2&quot;&gt;<br>    &lt;h1&gt;我是h1元素&lt;/h1&gt;<br>    &lt;p&gt;我是第1個段落元素&lt;/p&gt;<br>    &lt;h3&gt;我是h3元素&lt;/h3&gt;<br>    &lt;p&gt;我是第2個段落元素&lt;/p&gt;<br>    &lt;h3&gt;我是第2個h3元素&lt;/h3&gt;<br>    &lt;p&gt;我是第3個段落元素&lt;/p&gt;<br>    &lt;h3&gt;我是第3個h3元素&lt;/h3&gt;<br>    &lt;p&gt;我是第4個段落元素&lt;/p&gt;<br>    &lt;h5&gt;我是h5元素&lt;/h5&gt;<br>    &lt;p&gt;我是第5個段落元素&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/wRodeq">查看Demo(範例2)</a></p><blockquote><strong>否定虛擬類別</strong></blockquote><p>這個類別可以根據要排除的條件，一次選取其餘全部的元素，例如要做元素間的間距時很方便(除了第一個元素，其餘都設定 margin-top )。</p><p>E:not(s) (不含條件 s 的元素 E )</p><pre>※ 注意：s條件可以是「虛擬類別」、「id/class選擇器」或「類型選擇器」</pre><p>實作範例如下：</p><pre>&lt;html&gt;<br>&lt;head&gt;<br>  .my-list :not(:last-child) {<br>    color: #f00;<br>  }<br>  .wrap :not(.text-b) {<br>    color: #00f;<br>  }<br>  .block :not(p) {<br>    text-decoration: underline;<br>    color: #0f3;<br>  }<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;div class=&quot;wrap2&quot;&gt;<br>    &lt;h1&gt;我是h1元素&lt;/h1&gt;<br>    &lt;p&gt;我是第1個段落元素&lt;/p&gt;<br>    &lt;h3&gt;我是h3元素&lt;/h3&gt;<br>    &lt;p&gt;我是第2個段落元素&lt;/p&gt;<br>    &lt;h3&gt;我是第2個h3元素&lt;/h3&gt;<br>    &lt;p&gt;我是第3個段落元素&lt;/p&gt;<br>    &lt;h3&gt;我是第3個h3元素&lt;/h3&gt;<br>    &lt;p&gt;我是第4個段落元素&lt;/p&gt;<br>    &lt;h5&gt;我是h5元素&lt;/h5&gt;<br>    &lt;p&gt;我是第5個段落元素&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/maOwoz">查看Demo範例</a></p><blockquote><strong>目標虛擬類別</strong></blockquote><p>E:target ( 選取「點擊時」 href 路徑所指向的目標元素 E )</p><pre>※ 注意：這個虛擬類別，可以選取連結「目的地」的元素，而非連結本身的元素</pre><p>先設定好 a 元素的連結 # 名稱，再將對應的 id 名稱綁在要顯示的區塊 ul 上，接著將 ul 元素預設隱藏( display: none; )，<strong>只有在點擊 a 連結時，對應的目的地 ul 元素(ul:target)才會顯示出來( display: block; )，</strong>要注意的就是 :target 並不是綁在 a 元素，而是綁定在 a 元素連結指向的<strong>「ul 元素」</strong>。<br>如此，就用純 css 的寫法完成了一個簡易的展開收合 Menu。</p><pre>&lt;html&gt;<br>&lt;head&gt;<br>  ul {<br>    list-style: circle;<br>    display: none;<br>  }<br>  ul:target {<br>    display: block;<br>  }<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;div class=&quot;wrap&quot;&gt;<br>    &lt;a href=&quot;#content-1&quot; class=&quot;menu-btn&quot;&gt;Ｍenu 1&lt;/a&gt;<br>    &lt;ul id=&quot;content-1&quot;&gt;<br>      &lt;li&gt;list-01&lt;/li&gt;<br>      &lt;li&gt;list-02&lt;/li&gt;<br>      &lt;li&gt;list-03&lt;/li&gt;<br>    &lt;/ul&gt;<br>    &lt;a href=&quot;#content-2&quot; class=&quot;menu-btn&quot;&gt;Ｍenu 2&lt;/a&gt;<br>    &lt;ul id=&quot;content-2&quot;&gt;<br>      &lt;li&gt;list-01&lt;/li&gt;<br>      &lt;li&gt;list-02&lt;/li&gt;<br>      &lt;li&gt;list-03&lt;/li&gt;<br>    &lt;/ul&gt;<br>    &lt;a href=&quot;#content-3&quot; class=&quot;menu-btn&quot;&gt;Ｍenu 3&lt;/a&gt;<br>    &lt;ul id=&quot;content-3&quot;&gt;<br>      &lt;li&gt;list-01&lt;/li&gt;<br>      &lt;li&gt;list-02&lt;/li&gt;<br>      &lt;li&gt;list-03&lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uXm080Xc2YwuI3B9_ailFA.png" /><figcaption>點擊 a 元素(Menu 1) ，底下隱藏的 ul 元素就會顯示出來，可以切換點擊不同的 Menu</figcaption></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/gZLxqa">查看Demo範例</a></p><blockquote><strong>UI虛擬類別</strong></blockquote><p>可以依據<strong>「輸入表單的狀態」</strong>選擇元素的虛擬類別，可用來設定表單元素相鄰的 label 元素之樣式。</p><p>E:enabled (有效的表單元素 E )</p><p>E:disabled (禁用的表單元素 E )</p><p>E:checked (被選中的表單元素 E，例如單選/複選核取框)</p><p>實作範例如下：</p><pre>&lt;html&gt;<br>&lt;head&gt;<br>  /* 有效的input元素之label */<br>  .myform input:enabled + label {<br>    cursor: pointer;<br>  }<br>  .myform input:enabled + label:hover {<br>    color: #037ef3;<br>  }<br>  /* 禁用的input元素之label */<br>  .myform input:disabled + label {<br>    color: #ccc;<br>  }<br>  /* 已勾選的input元素之label */<br>  .myform input:checked + label {<br>    border-bottom: 3px double #037ef3;<br>  }<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;form class=&quot;myform&quot;&gt;<br>    &lt;input type=&quot;radio&quot; name=&quot;radio&quot; id=&quot;radio1&quot; value=&quot;1&quot; checked&gt;<br>    &lt;label for=&quot;radio1&quot;&gt;選項1&lt;/label&gt;<br>    &lt;input type=&quot;radio&quot; name=&quot;radio&quot; id=&quot;radio2&quot; value=&quot;2&quot;&gt;<br>    &lt;label for=&quot;radio2&quot;&gt;選項2&lt;/label&gt;<br>    &lt;input type=&quot;radio&quot; name=&quot;radio&quot; id=&quot;radio3&quot; value=&quot;3&quot;&gt;<br>    &lt;label for=&quot;radio3&quot;&gt;選項3&lt;/label&gt;<br>    &lt;input type=&quot;radio&quot; name=&quot;radio&quot; id=&quot;radio4&quot; value=&quot;4&quot; disabled&gt;<br>    &lt;label for=&quot;radio4&quot;&gt;選項4&lt;/label&gt;<br>  &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*8mNF-kZJRDz32_ibFFyWqg.png" /><figcaption>使用UI虛擬類別，可以依據表單元素輸入的狀態來設定想要的樣式</figcaption></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/pqNpGr">查看Demo範例</a></p><blockquote><strong>總結：<br>「～child」型虛擬類別並不區分元素的類型，而是將所有的子元素列入計算<br>「～of-type」型虛擬類別會將不同類型的元素依據類型分開計算<br>「否定虛擬類別」的條件可以是虛擬類別、id/class選擇器或類型選擇器<br>「目標虛擬類別」和「 UI虛擬類別」好好運用可以省下不少工<br>這些 CSS3 選擇器支援 IE 9 以上的版本</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c35ce1e867d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/css%E9%81%B8%E6%93%87%E5%99%A8%E4%BB%8B%E7%B4%B9-3-c35ce1e867d4">CSS選擇器介紹( 3)</a> was originally published in <a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A">UI/UX練功坊</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[display 屬性中常用的類別]]></title>
            <link>https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/display-%E5%B1%AC%E6%80%A7%E4%B8%AD%E5%B8%B8%E7%94%A8%E7%9A%84%E9%A1%9E%E5%88%A5-77eb86714d8a?source=rss-5ddd7d611b0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/77eb86714d8a</guid>
            <category><![CDATA[display]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[css3]]></category>
            <category><![CDATA[inline]]></category>
            <category><![CDATA[block]]></category>
            <dc:creator><![CDATA[Sandy]]></dc:creator>
            <pubDate>Fri, 14 Dec 2018 06:36:26 GMT</pubDate>
            <atom:updated>2019-04-24T05:11:00.744Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>介紹常用到的 display 種類分別有什麼特徵</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c4fmR4kr3x5wxt6FjxOy8Q.jpeg" /></figure><p>還記得剛開始寫css的時候<br>還沒弄清楚 float 和 display 的特性就在用了…<br>結果當然是常常切出來的畫面不如預期效果(挫折😂😂😂)&amp;亂解</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XiaH4cZCtkHmyLCGzRO7Tg.jpeg" /></figure><p>充分理解 css 屬性的特徵是很重要的，才能在運用時判斷正確<br>以下分別列出常用的種類之特徵，並以 CodePen 測試實際的狀況：</p><blockquote><strong>display: block</strong></blockquote><p>● 可以指定 寬度(width) 和 高度(height)<br>● 可以設定上下左右外距(margin)<br>● 可以設定上下左右內距(padding)<br>● 元素會由上而下「<strong>自動換行配置」</strong>(若有另外設定 float 或 position 時例外)<br>● <strong>無法設定垂直對齊</strong>(vertical-align)屬性，元素內容(文字)會永遠靠上對齊。但可以藉由 <strong>line-height 屬性</strong>解決文字內容垂直置中對齊的問題。<br>● 預設為此屬性的是區塊類型元素：div、ul、dl、p、h1~h6 …等</p><pre>.block {<br>  display: block;<br>  background-color: #f47721;<br>  width: 300px;<br>  height: 50px;<br>  margin: 30px;<br>  padding: 15px;<br>  vertical-align: middle; /*指定無效*/<br>  line-height: 50px; /*解決垂直置中對齊的辦法*/<br>  text-align: center;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*yrkQqNwFLF5kYpWo-eWFog.png" /></figure><blockquote><strong>display: inline</strong></blockquote><p>● <strong>「無法」</strong>指定寬度(width)和高度(height)，尺寸非固定會受 padding 值的影響<br>● 只能設定左右外距(margin-left &amp; margin-right)，<strong>「無法設定上下外距(margin-top &amp; margin-bottom)」<br></strong>● 可以設定上下左右內距(padding)<br>● 元素<strong>「不會自動換行配置」</strong>，只要沒有使用 br 元素強制換行，會在同一列一直顯示至空間不足才會換到下一行<br>● 相鄰的文字<strong>(同一列中)</strong>和 inline 元素之間可以垂直置中對齊<br>● 再搭配設定行高(line-height)的情況下，可以指定與相鄰文字的垂直對齊(vertical-align)方式(※但不包括自身文字內容)<br>● 預設為此屬性的是文字類型元素：span、a、strong、small …等</p><pre>.inline {<br>  display: inline;<br>  background-color: #7ac143;<br>  width: 300px; /*指定無效*/<br>  height: 150px; /*指定無效*/<br>  margin: 15px; /*只有左右有效，上下指定無效*/<br>  padding: 30px 15px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*bZH33V7ybKBfv4eFAtxXMA.png" /><figcaption>四邊都設定了 margin 也只會產生水平的推移(左右)，上下的外距不會改變，但 padding 值會保留</figcaption></figure><pre>.inline {<br>  display: inline;<br>  background-color: #7ac143;<br>  margin: 15px; /*只有左右有效，上下指定無效*/<br>  padding: 30px 15px;<br>  line-height: 90px;<br>  vertical-align: top;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6yQmV6UmyK7nH8bfTRRM5g.png" /><figcaption>搭配行高把間距撐開，就可以設定垂直對齊方式( vertical-align: top; )</figcaption></figure><blockquote><strong>display: inline-block<br>( 與 inline 一樣不會自動換行，但卻是以 block 元素盒子的方式顯示 )</strong></blockquote><p>● 可以指定 寬度(width) 和 高度(height)<br>● 可以設定上下左右外距(margin)<br>● 可以設定上下左右內距(padding)<br>● 元素<strong>「不會自動換行配置」</strong>，只要沒有使用 br 元素強制換行，會在同一列一直顯示至空間不足才會換到下一行<br>● 可在父元素設定 text-align 屬性，能指定區塊在父元素中的水平對齊方式<br>● <strong>可以設定垂直對齊</strong>(vertical-align)屬性，指定垂直對齊的方式<br>● 預設為此屬性的類型元素有：img、input、select、button …等</p><pre>.container {<br>  text-align: right; /*區塊在父元素中水平對齊的方式：左、中、右*/<br>}</pre><pre>.inline-block {<br>  display: inline-block;<br>  background-color: #00bce4;<br>  width: 90px;<br>  margin: 30px;<br>  padding: 15px;<br>  text-align: right; /*元素本身文字內容的水平對齊方式：左、中、右*/<br>  vertical-align: middle; /*區塊之間的垂直對齊方式：上、中、下*/<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U3SbrgFkQobZ5IJvbIrL2A.png" /></figure><blockquote><strong>display: table-cell</strong></blockquote><p>● 與 table 元素中的 th、td 顯示方式相同，可以解決 float 版面無法垂直對齊及無法設定高度一致的缺點，是比較早期 RWD 常見的做法(現在有 flex 可以用)。<br>● 若搭配將父元素屬性設定為 display: table，則可以將 table-cell 的寬度依據內容自動調適(與表格原理相同)<br>● 設定了 table-cell 的元素與表格儲存格一樣，會顯示在同一列<br>● 若沒有指定高度(或指定高度小於內容高度)，元素的高度會自動調整為<strong>與高度最大者相同</strong>(與表格原理相同)<br>● <strong>可以設定垂直對齊</strong>(vertical-align)屬性，可以設定垂直對齊方式(上/中/下)</p><pre>.table {<br>  display: table;<br>  margin: 30px;<br>}</pre><pre>.table-cell {<br>  display: table-cell;<br>  background-color: #ffffce;<br>  border: 1px solid #999;<br>  padding: 15px;<br>  margin: 15px; /*指定無效*/<br>  width: 25%;<br>  vertical-align: middle;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o4fHbA7lL4KKp8khBiX3kA.png" /><figcaption>若沒有指定高度，table-cell 的高度將統一為元素中高度最大者</figcaption></figure><blockquote><strong>display: none</strong></blockquote><p>● 該元素將<strong>「隱藏不顯示」</strong><br>● 該元素被視為不存在，<strong>不會在畫面上佔有空間</strong>，後續元素會自動遞補上</p><pre>.none {<br>  display: none;<br>}</pre><blockquote><strong>display: list-item<br>( 以 block 元素盒子的方式配置，但以條列式項目方式顯示，和 li 一樣 )</strong></blockquote><p>● 可以指定 寬度(width) 和 高度(height)<br>● 可以設定上下左右內距(padding)<br>● 可以設定上下左右外距(margin)<br>● 元素會由上而下「<strong>自動換行配置」<br></strong>● <strong>無法設定垂直對齊</strong>(vertical-align)屬性，元素內容(文字)會永遠靠上對齊。但可以藉由 <strong>line-height 屬性</strong>解決文字內容垂直置中對齊的問題。<br>● 可以搭配其他 list 的屬性(ex. list-style)自訂想要的條列項目樣式</p><pre>.list-item {<br>  display: list-item;<br>  background: #f1f1f1;<br>  width: 120px;<br>  height: 50px;<br>  padding: 20px;<br>  margin: 10px;<br>  list-style: circle;<br>  vertical-align: middle; /*指定無效*/<br>  line-height: 50px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*eNHT1OxNhh15pTw-N4T1VQ.png" /></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/EGVVje?editors=1100"><strong>查看以上的範例Demo</strong></a></p><blockquote>總結：將以上提到的 display 屬性特徵整理如下表：</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uVrG5CwY6uXmCOs3mNbv6w.png" /></figure><p>inline屬性 → 可以與其他元素排成同一列<br>block屬性 → 可以設置寬高尺寸<br>inline-block → 既可以與其他元素排成同一列又可以設置寬高尺寸</p><p>在製作水平排列選單( nav )時，若不需要指定尺寸可用 display: inline;，若需要指定尺寸用 display: block; 搭配 float: left; 會比較方便</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77eb86714d8a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/display-%E5%B1%AC%E6%80%A7%E4%B8%AD%E5%B8%B8%E7%94%A8%E7%9A%84%E9%A1%9E%E5%88%A5-77eb86714d8a">display 屬性中常用的類別</a> was originally published in <a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A">UI/UX練功坊</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[position 屬性的基礎概念]]></title>
            <link>https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/position-%E5%B1%AC%E6%80%A7%E7%9A%84%E5%9F%BA%E7%A4%8E%E6%A6%82%E5%BF%B5-5931254e5203?source=rss-5ddd7d611b0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5931254e5203</guid>
            <category><![CDATA[sticky]]></category>
            <category><![CDATA[css3]]></category>
            <category><![CDATA[position]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Sandy]]></dc:creator>
            <pubDate>Mon, 03 Dec 2018 13:26:40 GMT</pubDate>
            <atom:updated>2018-12-03T13:26:40.578Z</atom:updated>
            <content:encoded><![CDATA[<p>好好運用position屬性就能做出自由度更高更靈活的排版</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uFjJfOO1xX6pzDQROvuflQ.jpeg" /></figure><p>先來看 css 的 position 屬性有哪些值：<br><strong>static (預設值)、absolute (絕對配置)、relative (相對配置)、fixed (固定配置)，</strong>以及 css3 才加入的新屬性值 <strong>sticky</strong></p><p><strong>position: absolute 絕對配置</strong></p><p>將某個區塊設定 position: absolute 之後，<strong>這個區塊就像在白板上貼便利貼一樣</strong>，可以脫離原本預設的版面配置，重新以<strong>「基準元素」</strong>為起點，可以自由指定配置位置。而原本應該顯示這個區塊的位置，由於這個區塊移到新的圖層(便利貼)了，後續的元素會自動遞補上去。</p><p>若沒有指定基準元素的話，<strong>預設是以 body 元素(整個視窗)為基準</strong>。我們來看下列這個範例，設定好 Box1 的屬性之後，它就從原本應該出現的位置，位移到目前的位置了(距離視窗上方80px、左方200px)</p><pre>.box1 {<br>  position: absolute;<br>  top: 80px;<br>  left: 200px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YzrUifszFHK1e2vySTwZ9w.png" /><figcaption>基準元素預設為 body</figcaption></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/gQZBGb">查看範例一</a></p><p>但假如我們將 #wrap 設定為<strong>「基準元素」：position 屬性必須是relative (且必須為絕對配置元素的父元素或祖先元素)，</strong>我們配置的位置數值就會以 #wrap 的範圍來做計算。指定好基準元素後，它又從剛剛的位置，位移到距離 #wrap 區塊上方80px、左方200px 的位置。</p><pre>#wrap {<br>  border: 3px solid #00f;<br>  position: relative; /*表示它是基準元素*/<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EIXLSMjGCMkiHehqUceoGA.png" /><figcaption>設定父元素 #wrap 為基準元素後</figcaption></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/zMyMxe">查看範例一修改後</a></p><p><strong>● 補充說明1：left、top、right、bottom 這個語法只有當 position 屬性值不是 static (預設值) 時才有效</strong>，當指定的數值為<strong>「負值」</strong>時，可以將配置位置拉到基準元素外側。下圖為指定 left: -120px 的結果。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D3ylDv_I96_Vg0qr5iUm0w.png" /><figcaption>當位移的數值為負數時，可以配置到基準元素的外側</figcaption></figure><p><strong>● 補充說明2：z-index (元素在 z 軸的方向順序)這個語法同樣也是只有當 position 屬性值不是 static (預設值) 時才有效</strong>，預設版面的 z-index 值視為 0 ，要讓區塊顯示於下方時，必須將 z-index 的數值設為<strong>「負數」</strong>，例如以下範例：</p><pre>.box1 {<br>  position: absolute;<br>  top: 80px;<br>  left: -70px;<br>  z-index: -1;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a3Vd1ybSCcyAZRxY8h7LfQ.png" /><figcaption>設定 z-index 為負值，讓 Box1 顯示在 #wrap 的下方(下一層)</figcaption></figure><p>※ 註：當有多個屬性值不為 static(預設值)的元素重疊時，若不做 z-index 的設定，預設顯示時會依「<strong> HTML 的撰寫順序，順序越後者顯示在越上層」</strong></p><p><strong>position: relative 相對配置</strong></p><p>剛剛介紹的 position: absolute 是可以設定父層元素為基準元素作絕對位移，而 position: relative 則會以<strong>「自己原本顯示的位置為基準位置」</strong>來指定上下左右的偏移，且<strong>區塊原本的空間仍會保留不會消失</strong>。</p><p>這個屬性值大多會用在：<br>(1) 設定絕對配置( position: absolute )的基準元素時<br>(2) 希望元素偏移重疊 or 指定圖層上下順序且<strong>同時保留原本的空間</strong>時</p><p>(✓) 例如當我們希望做一個色塊重疊的效果，但是又不希望底下的介紹文字浮上來被色塊遮住時，就可以這樣設定：</p><pre>.box3 {<br>  position: relative;<br>  top: -20px;<br>  left: 160px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ixhHEccJ6o3OT_92epw5Ig.png" /><figcaption>將 Box3 設定為 position: relative; 時，原本的區塊空間會被保留，所以文字不會自動填補上來</figcaption></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/VVRrQw">查看範例二</a></p><p>(✖) 但假如使用 position: absolute 的話，雖然同樣也可以達到偏移的效果，但是區塊原本佔的空間消失了，後續的文字就自動填補上來了。</p><pre>.box3 {<br>  position: absolute;<br>  top: 370px;<br>  left: 190px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vuxyQNxpVFIksqkh8LcC-Q.png" /><figcaption>若將 Box3 設定為 position: absolute; ，原本的區塊空間會消失，文字就自動填補上來了</figcaption></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/XyGVRr">查看範例二修改後</a></p><p><strong>position: fixed 固定配置</strong></p><p>position: fixed 和 position: absolute 一樣，都是以絕對位置配置元素區塊，不同的是，fixed 是以整個視窗( body 元素)為基準，就算拉動捲軸，區塊仍然會顯示在同一個位置。</p><p>這種特性可以使用在 go top (回到頁面頂端)按鈕 或是 固定顯示於頁面上方的 header 等，我們來做一個返回頁面頂端的按鈕試試看，先設定好按鈕的樣式後，加入 position: fixed 的設定，固定顯示在頁面右下方：</p><pre>#gotop_btn {<br>  position: fixed;<br>  bottom: 10px;<br>  right: 20%;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LSEiqV97i1UZwtBaORU3JA.png" /><figcaption>按鈕設定為 position: fixed 的絕對位置，不管頁面捲動到哪，都固定顯示在頁面的右下方</figcaption></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/rQRJyj">查看 position: fixed; 範例</a></p><p><strong>position: sticky</strong></p><p>最後來看 sticky 這個新屬性值的效果，它是 relative 及 fixed 兩種 position 的混合，默認的情況下，元素會被當作 <strong>position: relative;</strong> ，捲動頁面時元素會跟著父元素一起捲動，但是當元素與視窗的距離小於指定的數值時(例如下列範例是 top: 15px )，元素則會轉換為 <strong>position: fixed;</strong>，固定黏著( sticky )在指定的數值上，距離不會再縮小。</p><p>我們來寫一個 sticky sidemenu 看看實際效果：</p><pre>.sidemenu {<br>  width: 20%;<br>  float: left;<br>  padding-top: 15px;<br>  position: sticky;<br>  top: 15px;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RTM5dUaxgDMQdmgAwDMFmQ.png" /><figcaption>一開始 sidemenu 的位置是在距離上方 header 15px 的地方</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*likr3AD3jmE4BeXTrRl2YQ.png" /><figcaption>往下捲動之後，sidemenu 就會一直黏著( sticky )在距離視窗上方 15px 的地方，不會往上捲出去</figcaption></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/oQVqrX">查看 sticky sidemenu 範例</a></p><p>另外，也可以達成像索引文字開頭這樣的黏著 menu 效果，我們來看這個 MDN 提供的範例：<a href="https://jsfiddle.net/lotabout/hjf99x20/?utm_source=website&amp;utm_medium=embed&amp;utm_campaign=hjf99x20">→ MDN 範例連結</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0pgxazCF836CCt--Llqu4Q.png" /><figcaption>一開始文字開頭索引看起來跟靜態的沒什麼差別</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZbHVQwVjzjffk96gI_wDuA.png" /><figcaption>往下捲動後，文字開頭會黏著在頁面的最上方</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mk-sSwc6DOfjdp8x-TwnhQ.png" /><figcaption>當捲動超出父元素的範圍時，上一個文字開頭會捲出畫面，繼續黏著下一個文字開頭</figcaption></figure><p>以上這兩種範例的效果，用 sticky 這個屬性值只需要純 CSS 就能實現，原本沒有這個屬性時，我們需要撰寫 JS 的滾動監聽才能實現。</p><p>但最重要的是，這個屬性的支援度到底如何，我們來看 MDN 提供的資訊：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jj2ndAJxviQxyP-j7OdGQA.png" /><figcaption>支援的瀏覽器有 Chrome 版本 56 以上, Edge, Firefox, Safari 等，IE 不支援。但要注意的是 Chrome 跟 Opera 都不支援 table 元素使用 sticky 這個屬性</figcaption></figure><blockquote>總結：<br>position 屬性雖然很好用，但是在大小不固定的區塊(基準元素)使用絕對配置時，內容很可能會超出區域外出現 bug，因此在使用時一定要慎重考慮如何設計並多加測試，儘量以用在較簡化的地方為佳。</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5931254e5203" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/position-%E5%B1%AC%E6%80%A7%E7%9A%84%E5%9F%BA%E7%A4%8E%E6%A6%82%E5%BF%B5-5931254e5203">position 屬性的基礎概念</a> was originally published in <a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A">UI/UX練功坊</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[解除 float 屬性的方法]]></title>
            <link>https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/%E8%A7%A3%E9%99%A4-float-%E5%B1%AC%E6%80%A7%E7%9A%84%E6%96%B9%E6%B3%95-5e29cc30777d?source=rss-5ddd7d611b0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e29cc30777d</guid>
            <category><![CDATA[overflow]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[clearfix]]></category>
            <category><![CDATA[clear]]></category>
            <category><![CDATA[float]]></category>
            <dc:creator><![CDATA[Sandy]]></dc:creator>
            <pubDate>Tue, 27 Nov 2018 10:43:49 GMT</pubDate>
            <atom:updated>2018-12-03T13:45:15.287Z</atom:updated>
            <content:encoded><![CDATA[<p>使用 float 屬性時一定要清除浮動，否則會有版面錯置或失去高度的情形</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pvN2pomTge67dtEoU9OqpA.jpeg" /></figure><p>在使用 float 屬性排列區塊時，假如沒有清除浮動<br>常常會有父層高度消失(抓不到)的情形…<br>或是底下的區塊擠上來造成版面錯置的情況<br>所以一定要記得有使用 float，就要解除 float 屬性的影響<br>可以分成以下兩種情形：</p><p><strong>(1) 在後續兄弟元素中解除 float</strong></p><p>假如需要在同一層級的元素中解除 float，只需要在要恢復預設顯示方式的區塊上加上「 <strong>clear 屬性」</strong>，就可以解除 float 的影響了。基本上 float 跟 clear 可視為一組成對的指令來使用。<br>在下列範例中，我們沒有把 menu 跟 content 的寬度剛好填滿，保留一些間距，此時若沒有解除 float，後續元素就會自動填補上來，造成版面錯置</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6d4-ce9fJBEsbPHEeIH91g.png" /><figcaption>↑ 沒有清除浮動時，只要有空間後續元素就會擠上去</figcaption></figure><p>此時只要在 <strong>footer 區塊中加入屬性 clear:both;(屬性值有 left/right/both) </strong>就不會有文繞圖的情形發生了，也保留了我們需要的區塊間距。<br>※ 注意：假如設定了 clear 屬性，margin-top 就會失去作用，若想要設定 footer 與上面區塊的間距，要在 menu 或 content 中設定 margin-bottom</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y7yPX4dFnX9PWPEEOyPu0w.png" /><figcaption>↑ 清除浮動影響後，版面顯示就正常了</figcaption></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/JeBVWw">查看範例Demo</a></p><p><strong>(2) 在父層元素中解除float</strong></p><p>在下列這個範例中，使用 float 的區塊跟 footer 區塊並不在同一層，float 的區塊有用一個 div 父層 #main 包起來，此時就算我們在底下的 <strong>footer 設定了 clear:both; </strong>用開發者工具查看時會發現 div#main 這個父層的高度是 0，表示沒有抓到子元素的高度<strong>(視為無高度)</strong>。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ySpNzmfu0WCUafmUFpM1vA.png" /><figcaption>↑ 當子元素設為 float，沒有清除浮動時，父層元素視為「無高度」</figcaption></figure><p>此時要清除 float 就必須在跟 content 同一層的最後增加一個虛擬的元素，在虛擬元素加上 clear 屬性，如此一來即使 HTML 中實際上並沒有這個元素，還是可以在父層元素中解除 float 的影響。<br>這個方式我們通稱為<strong>「clearfix」</strong>，是一個 css 的虛擬元素：<br><strong>( ※ 據測試統計結果，好像使用 display: table 的穩定度最高 )</strong></p><pre>.clearfix:after {<br>  content: “”;<br>  display: block;<br>  clear: both;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WvVdNt9XaGVS3-1Eas_G4Q.png" /><figcaption>↑ 在父層元素加上.clearfix清除浮動後，父層的高度就正常顯示了</figcaption></figure><p>→ <a href="https://codepen.io/lin-hsienli/pen/NEBVgz">查看範例Demo2</a></p><p>除此之外，還有一個快速便捷的方法可以清除浮動，就是在父層元素設定 overflow 屬性，一樣有解除 float 影響的效果，但是 overflow 原本的用途是在<strong>「指定超出範圍的內容隱藏/顯示/捲動」</strong>，在使用時必須注意，在設計上可能會無法使用。</p><pre>#main { overflow: hidden; }</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/PxBrxr">查看範例Demo3</a></p><blockquote>總結剛剛說的：<br>有後續的兄弟元素時，用 clear: both; 解除 float<br>無後續元素需要在父元素解除 float 時，使用 clearfix 或 overflow<br>比起 float 的排版方式(左右浮動)，使用 flex可以做到的版面設定更多元<br>之後再來詳細整理 flex 的用法</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e29cc30777d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/%E8%A7%A3%E9%99%A4-float-%E5%B1%AC%E6%80%A7%E7%9A%84%E6%96%B9%E6%B3%95-5e29cc30777d">解除 float 屬性的方法</a> was originally published in <a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A">UI/UX練功坊</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS的優先順位]]></title>
            <link>https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/css%E7%9A%84%E5%84%AA%E5%85%88%E9%A0%86%E4%BD%8D-cfb859e988bd?source=rss-5ddd7d611b0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfb859e988bd</guid>
            <category><![CDATA[specificity]]></category>
            <category><![CDATA[important]]></category>
            <category><![CDATA[selectors]]></category>
            <category><![CDATA[css3]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Sandy]]></dc:creator>
            <pubDate>Thu, 22 Nov 2018 08:10:22 GMT</pubDate>
            <atom:updated>2018-11-22T08:10:22.087Z</atom:updated>
            <content:encoded><![CDATA[<p>載入位置＆撰寫順序＆選擇器類型都會影響 css 的優先順位</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*miCknE5_j5fjhicX4sD6xg.jpeg" /></figure><p>在介紹 CSS 的優先順位之前，<br>先講一下在 HTML 中套用 CSS 的方法，共有三種：</p><p><strong>① 行內(inline)套用：</strong><br>直接在 HTML 標籤中使用 style 屬性指定 CSS 樣式</p><pre>&lt;h1 style=&quot;color: #ff0000;&quot;&gt;主標題&lt;/h1&gt;</pre><p>雖然這個方法最直覺，但通常我們在撰寫 CSS 時使用的樣式繁多，為了保持 HTML 的結構乾淨清楚，原則上不會採用這種方法。且 CSS 選擇器有許多進階的用法必須另外撰寫才能使用，將結構與設計分開，已是目前 web 設計的主流了。</p><p><strong>② HTML 內部載入：<br></strong>在 HTML 文件的 head 元素中，使用 style 元素將 CSS 撰寫其內</p><pre>&lt;head&gt;<br>  &lt;style&gt;<br>    h1 { color: #ffffff; }<br>  &lt;/style&gt;<br>&lt;/head&gt;</pre><p>這麼做雖然可以將 CSS 的內容與 HTML 原始碼分開，但寫在 head 元素中的 CSS 就只能在這一個網頁使用，一般是建議少用這種方式，除非是有特殊的狀況需要覆蓋某些樣式。</p><p><strong>③ 外部載入CSS：</strong><br>將 CSS 程式碼統一存成一個外部檔案(.css)，再到 HTML 的 head 元素中載入這個檔案。可使用 link 元素或是 ＠import 這兩種方法來載入，<strong>通常使用 link 元素載入</strong>。</p><pre>&lt;head&gt;<br>  &lt;style&gt;<br>    @import url(https://medium.com/%E5%A4%96%E9%83%A8css%E6%AA%94%E6%A1%88%E7%9A%84%E8%B7%AF%E5%BE%91);<br>  &lt;/style&gt;<br>&lt;/head&gt;</pre><p>或是</p><pre>&lt;head&gt;<br>    &lt;link href=&quot;外部css檔案的路徑&quot; rel=&quot;stylesheet&quot; media=&quot;all&quot;&gt;<br>&lt;/head&gt;</pre><p>在 HTML 中套用 CSS，最常見的就是這個方式。這個方法的優點是多個網頁可以共用同一個 CSS，這樣維護檔案相對比較容易。<br>一般來說，CSS 的管理可分割為 網站共通的 CSS、首頁專用的 CSS、下層子頁面另外使用的 CSS 等，再依狀況分別載入需要的 CSS 檔案。<br><strong>不過要注意，建立太多 CSS 檔案可能會造成顯示速度變差，所以若非網站的規模非常龐大或 CSS 的資料量相當多，大致上不會分割太多太細的 CSS 檔案，主要目的還是取出可共用的 CSS 檔案一起管理。</strong></p><p>那麽，這三個套用方法，CSS 讀取時的優先順位是怎麼排的呢? 答案是以越直接的方式套用 CSS 優先權就越大：</p><h4><strong>行內(inline)套用CSS ＞ HTML內部載入CSS ＞ 外部載入CSS</strong></h4><p>除了套用方法之外，還有 CSS 的撰寫順序以及選擇器的類型也會影響 CSS 的的優先權：<br>CSS 的撰寫順序基本上是以<strong>「寫在後面的敘述，優先於寫在前面的敘述」</strong>為原則，只要後面衝突到同一個位置的值就會覆寫過去。<br>另外，CSS 選擇器類型的明確度(Specifity)優先順位是：<strong>id選擇器 ＞ class選擇器 ＞ 標籤元素</strong><br>總結以上，我們可以將剛剛說到的 CSS 優先順位整理為底下這張圖：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sN7G0rOAM3tVLsmL4Ew8cw.jpeg" /></figure><p>但在無法使用以這些順位修改覆蓋 CSS 時，有一種寫法可以直接忽略 CSS 的明確度，直接指定為最優先，就是在屬性後面加上<strong>「 !important」</strong></p><pre>&lt;head&gt;<br>  &lt;style&gt;<br>    #main-title { color: red; }<br>    .title { color: blue !important; }<br>  &lt;/style&gt;<br>&lt;/head&gt;</pre><pre>&lt;h1 id=&quot;main-title&quot; class=&quot;title&quot; style=&quot;color: purple;&quot;&gt;主標題&lt;/h1&gt;</pre><p>例如上面這個範例，正常來說，標題應該會是紫色的，因為行內套用 CSS 的優先權最高，但只要在選擇器的屬性後面加上 <strong>!important</strong>，就可以直接取得最高優先權，所以標題會變成藍色的。<br><a href="https://codepen.io/lin-hsienli/pen/NEyoPQ">查看範例 Demo →</a></p><p>想要覆蓋選擇器後面加上的 <strong>!important</strong>，唯一的方法就是在行內套用的 CSS 中直接加上 <strong>!important</strong>，例如下列這個範例，標題就變成紫色的了</p><pre>&lt;head&gt;<br>  &lt;style&gt;<br>    #main-title { color: red; }<br>    .title { color: blue !important; }<br>  &lt;/style&gt;<br>&lt;/head&gt;</pre><pre>&lt;h1 id=&quot;main-title&quot; class=&quot;title&quot; style=&quot;color: purple !important;&quot;&gt;<br>  主標題<br>&lt;/h1&gt;</pre><p><a href="https://codepen.io/lin-hsienli/pen/xQYMrY">查看範例 Demo2 →</a></p><blockquote><strong>要注意的是 !important是在沒有更好的辦法時才建議使用的，若胡亂使用，可能會破壞 CSS 原始的規則，導致要修改時找不到屬性撰寫的位置， CSS看起來也會很雜亂，原則上應儘量避免使用才是比較優良的撰寫方式。</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfb859e988bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/css%E7%9A%84%E5%84%AA%E5%85%88%E9%A0%86%E4%BD%8D-cfb859e988bd">CSS的優先順位</a> was originally published in <a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A">UI/UX練功坊</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS選擇器介紹( 2 )]]></title>
            <link>https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/css%E9%81%B8%E6%93%87%E5%99%A8%E4%BB%8B%E7%B4%B9-2-5c65aed03184?source=rss-5ddd7d611b0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c65aed03184</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[attributes]]></category>
            <category><![CDATA[css3]]></category>
            <category><![CDATA[selectors]]></category>
            <dc:creator><![CDATA[Sandy]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 05:59:58 GMT</pubDate>
            <atom:updated>2018-11-21T07:56:53.285Z</atom:updated>
            <content:encoded><![CDATA[<p>css屬性選擇器介紹</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VD_lgMkoBQhSkranTgniyg.jpeg" /></figure><p>● <strong>屬性選擇器(Simple attribute selector)：</strong></p><p><strong>元素名稱[屬性名稱]</strong></p><p>選擇具有某html屬性的元素標籤<br>例如下列範例的意思就是選擇具有href屬性的a元素</p><pre>a[href] { color: #ff0000; }</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/jQYpOY">看Demo範例1</a></p><p>假如想要指定多個屬性的話，只需要接續寫出[屬性名稱]就可以了<br>寫成 — <strong>元素名稱[屬性名稱][屬性名稱]<br></strong>例如下列範例就是選擇同時具有href屬性和title屬性的a標籤的意思</p><pre>a[href][title] { color: #00ff00; }</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/jQYpOY">看Demo範例2</a></p><p>● <strong>準確屬性選擇器(Exact attribute value selector)：</strong></p><p><strong>元素名稱[屬性名稱=“屬性值”]</strong></p><p>只選擇具有特定屬性值的元素標籤<br>例如下列範例的意思就是選擇target屬性值為_blank的a元素</p><pre>a[target=&quot;_blank&quot;] { color: #00ffff; }</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/jQYpOY">看Demo範例3</a></p><p>與前一個範例相同，也可以指定多個特定屬性值，只需要接續寫出就可以了寫成 — <strong>元素名稱[屬性名稱=“屬性值”][屬性名稱=“屬性值”]<br></strong>下列範例是選擇同時有 <strong>href屬性為https://www.google.com.tw/ </strong>和 <strong>target屬性值為_blank </strong>的a標籤</p><pre>a[href=&quot;<a href="https://www.google.com.tw/">https://www.google.com.tw/</a>&quot;][target=&quot;_blank&quot;] { color: #cccccc; }</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/jQYpOY">看Demo範例4</a></p><p><strong>CSS3 新增的 部份屬性選擇器(Partial value attribute selector) <br>註：IE9 以上支援</strong></p><p>● <strong>元素名稱[屬性名稱^=“特定開頭”]：<br></strong>選擇具有特定屬性，且屬性值是以<strong>“特定開頭”</strong>的元素標籤<br>例如下列範例就是具有class名稱開頭為green的p元素會變成綠色<br>發現結果第三行是黑色，第四行才是綠色<br>也就是說不只單字的開頭，還要放在第一個值，這個寫法才會生效</p><pre>&lt;style type=&quot;text/css&quot;&gt;<br>    p[class^=&quot;green&quot;] { color: #34bf49; }<br>&lt;/style&gt;<br><br>&lt;div&gt;<br>    &lt;p class=&quot;greenText&quot;&gt;我是綠色我是綠色我是綠色&lt;/p&gt;<br>    &lt;p class=&quot;green-text&quot;&gt;我是綠色我是綠色我是綠色&lt;/p&gt;<br>    &lt;p class=&quot;Bigger greenText&quot;&gt;我不是綠色&lt;/p&gt;<br>    &lt;p class=&quot;greenText Bigger&quot;&gt;我是綠色我是綠色我是綠色&lt;/p&gt;<br>    &lt;p class=&quot;green&quot;&gt;我是綠色我是綠色我是綠色&lt;/p&gt;<br>    &lt;p class=&quot;lightgreen-text&quot;&gt;我是淺綠色&lt;/p&gt;<br>&lt;/div&gt;</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/jQYpOY">看Demo範例5</a></p><p>● <strong>元素名稱[屬性名稱$=“特定結尾”]：<br></strong>選擇具有特定屬性，且屬性值是以<strong>“特定結尾”</strong>的元素標籤<br>例如下列範例就是具有class名稱結尾為purple的p元素會變成紫色<br>我們發現第三行仍然是黑色沒有變成紫色<br>也就是說不只單字的結尾，還要放在最後一個值，這個寫法才會生效</p><pre>&lt;style type=&quot;text/css&quot;&gt;<br>    p[class$=&quot;purple&quot;] { color: #7d3f98; }<br>&lt;/style&gt;<br><br>&lt;div&gt;<br>    &lt;p class=&quot;textpurple&quot;&gt;我是紫色我是紫色我是紫色&lt;/p&gt;<br>    &lt;p class=&quot;Bigger textpurple&quot;&gt;我是紫色我是紫色我是紫色&lt;/p&gt;<br>    &lt;p class=&quot;textpurple Bigger&quot;&gt;我是黑色我是黑色&lt;/p&gt;<br>    &lt;p class=&quot;purple&quot;&gt;我是紫色我是紫色我是紫色&lt;/p&gt;<br>&lt;/div&gt;</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/jQYpOY">看Demo範例6</a></p><p>● <strong>元素名稱[屬性名稱*=“特定字眼”]：<br></strong>選擇具有特定屬性，且屬性值包含<strong>“特定字眼”</strong>的元素標籤<br>例如下列範例就是選擇所有class名稱包含big(不論位置在開頭/中間/結尾)的元素標籤都適用</p><pre>*[class*=&quot;big&quot;] { border: 1px solid #333; }</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/jQYpOY">看Demo範例7</a></p><p>● <strong>元素名稱[屬性名稱~=“特定單詞”]：</strong><br>當元素的屬性值可用空白隔開設定多個值時，若其中有一個值為特定單詞<strong>(一定要完全符合)</strong>，則套用樣式<br>我們可以發現下列範例的最後三行才是藍色文字，其他都不符合套用規則</p><pre>&lt;style type=&quot;text/css&quot;&gt;<br>    *[class~=&quot;blue&quot;] { color: #037ef3; }<br>&lt;/style&gt;<br><br>&lt;div&gt;<br>    &lt;p class=&quot;textblue&quot;&gt;我不是blue我不是blue&lt;/p&gt;<br>    &lt;p class=&quot;Bigger text-blue&quot;&gt;我不是blue我不是blue&lt;/p&gt;<br>    &lt;p class=&quot;bluetext Bigger&quot;&gt;我不是blue我不是blue&lt;/p&gt;<br>    &lt;p class=&quot;blue&quot;&gt;我是blue我是blue我是blue&lt;/p&gt;<br>    &lt;p class=&quot;blue Bigger&quot;&gt;我是blue我是blue我是blue&lt;/p&gt;<br>    &lt;p class=&quot;Bigger blue&quot;&gt;我是blue我是blue我是blue&lt;/p&gt;<br>&lt;/div&gt;</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/jQYpOY">看Demo範例8</a></p><p><strong>CSS3 新增的 特定屬性選擇器(Particular attribute selector)<br>註：IE9 以上支援</strong></p><p>● <strong>元素名稱[屬性名稱|=“特定開頭”]：<br></strong>以下列範例來說，當元素為p，並具有class屬性，且class屬性的值為red、red-或<strong>以</strong>red-<strong>開頭</strong>時，則套用樣式<br><strong>若具class屬性，以red開頭，但是值不為red，則不會套用樣式<br>此時寫成 元素名稱[屬性名稱^=“特定開頭”]就可適用，但要放在第一個值</strong></p><pre>&lt;style type=&quot;text/css&quot;&gt;<br>    p[class|=&quot;red&quot;] { color: Red; }<br>&lt;/style&gt;<br><br>&lt;div&gt;<br>    &lt;p class=&quot;red&quot;&gt;我是Red我是Red我是Red&lt;/p&gt;<br>    &lt;p class=&quot;red-&quot;&gt;我是Red我是Red我是Red&lt;/p&gt;<br>    &lt;p class=&quot;red-text&quot;&gt;我是Red我是Red我是Red&lt;/p&gt;<br>    &lt;p class=&quot;redtext&quot;&gt;我不是Red我不是Red&lt;/p&gt;<br>    &lt;p class=&quot;Textred&quot;&gt;我不是Red我不是Red&lt;/p&gt;<br>&lt;/div&gt;</pre><p>→ <a href="https://codepen.io/lin-hsienli/pen/jQYpOY">看Demo範例9</a></p><blockquote>雖然css3新增的屬性選擇器很方便，但是在使用時務必要考慮好class的命名，否則會發生很多重複選取的情形，class的套用就會很雜亂<br>再複習一次剛剛說的：<br><strong>e[attr^=“val”] 指定特定屬性值開頭，且要放在第一個值<br>e[attr$=“val”] 指定特定屬性值結尾，且要放在最後一個值<br>e[attr*=“val”] 指定屬性值包含特定字眼，位置與命名方式不拘<br>e[attr~=“val”] 指定特定單詞，整個值要完全相同，順序不拘<br>e[attr|=“val”] 指定特定屬性值開頭，但要符合val-開頭的命名方式</strong></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c65aed03184" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/css%E9%81%B8%E6%93%87%E5%99%A8%E4%BB%8B%E7%B4%B9-2-5c65aed03184">CSS選擇器介紹( 2 )</a> was originally published in <a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A">UI/UX練功坊</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS選擇器介紹( 1 )]]></title>
            <link>https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/css%E9%81%B8%E6%93%87%E5%99%A8%E4%BB%8B%E7%B4%B9-1-ec19bc5b33a?source=rss-5ddd7d611b0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec19bc5b33a</guid>
            <category><![CDATA[selectors]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[css3]]></category>
            <dc:creator><![CDATA[Sandy]]></dc:creator>
            <pubDate>Thu, 15 Nov 2018 10:35:51 GMT</pubDate>
            <atom:updated>2018-12-17T08:51:33.622Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>包括最基礎的 css選擇器用法</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VPuLLu2qbttoVRP71QGY2g.jpeg" /></figure><p>開始學習撰寫css的時候，最常用的選擇器就是<strong>類別(元素)、id、class </strong>這三種最直覺的用法：</p><p>● <strong>類別(元素)選擇器</strong>：直接將指定的元素標籤名稱當做選擇器，例如下列範例：樣式會套用到頁面中所有的&lt;h1&gt;~&lt;/h1&gt;，較適合用來定義全體通用的基礎樣式。</p><pre>h1 { color: #333333; }</pre><p>● <strong>id選擇器</strong>：利用 id 屬性為元素命名並做為選擇器，元素(標籤)名稱通常省略不寫。<br><strong>※ 注意：id 是用來識別在 HTML 檔案中特定位置的屬性，一個 HTML 檔中只能有一個，若在同一個頁面中撰寫多次相同的 id 名稱，將會造成語法錯誤</strong>。</p><pre>#title { text-align: center; }</pre><p>● <strong>class選擇器</strong>：利用 class 屬性為元素命名並做為選擇器，省略元素(標籤)名稱時，將被視為<strong>通用的 class，任何元素標籤都可以使用，可以在 HTML 檔中多處重複使用</strong>。</p><pre>.text-green { color: #32b16c; }</pre><p>假如不省略元素(標籤)名稱時則只有特定的元素才適用。例如下列這個就只有 h1 標籤套用此 class 才有效。</p><pre>h1.text-green { color: #32b16c; }</pre><p>另外多補充一個由 class 延伸的選擇器</p><p>● <strong>複合選擇器</strong>：當設定多個 class 時，可以用「.class1.class2」的形式將選擇器結合在一起<strong>( class 中間不可有空格)</strong>，如此可以指定出<strong>「既有class1也有class2」</strong>的選擇器</p><pre>.cat-type.male { color: #2793a7; }</pre><p>以上說的前三種選擇器：<strong>類別(元素)、id、class</strong>都是用於單一元素標籤、單一class、單一id的選擇器，稱之為<strong>「簡易選擇器」</strong>。</p><p>除了最基本的<strong>簡易選擇器</strong>之外，還有許多 css 選擇器，例如<strong>通用選擇器、群組選擇器、子孫選擇器、子選擇器、相鄰選擇器</strong>等，以下一一介紹用法：</p><p>● <strong>通用選擇器</strong>：將樣式套用於全部元素標籤中，通常在 reset css 時才會用到此方法。</p><pre>* { margin: 0px; padding: 0px; }</pre><p>● <strong>群組選擇器</strong>：利用<strong>「逗號」</strong>串連多個選擇器一併管理的用法，這樣可以將多處不同樣式一次指定，避免重複撰寫相同的 class 內容。</p><pre>h1,h2,h3 { color: #333333; }<br>.main-title, .sub-title, .small-title { font-weight: bold; }</pre><p>● <strong>子孫選擇器</strong>：利用元素間的親子關係，依序由<strong>「父元素→子元素→孫元素 」</strong>的形式特定出範圍的選擇器。<br>注意：<strong>必須依序以「半形空格」分隔並列出元素標籤</strong></p><pre>#main-list ul li a { color: #ff0000; }</pre><p>但假如能明確的辨識出目的元素，不會與其他用途的標籤混淆，省略中間的元素直接寫目的元素也是可以的，例如上列可以改為：</p><pre>#main-list a { color: #ff0000; }</pre><p>● <strong>子選擇器( &gt; )</strong>：與子孫選擇器(任意的後代元素皆選)不同，<strong>子選擇器是只選擇子元素，子元素的子元素(孫元素)的樣式並不受影響</strong>，例如：</p><pre>&lt;!DOCTYPE HTML&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;style type=&quot;text/css&quot;&gt;<br>    li { color: #333333; }</pre><pre>    .main-menu &gt; li { color: #ff0000; }<br>  &lt;/style&gt;<br>&lt;/head&gt;</pre><pre>&lt;body&gt;<br>&lt;ul class=&quot;main-menu&quot;&gt;<br>  &lt;li&gt;項目1&lt;/li&gt;<br>  &lt;li&gt;項目2&lt;/li&gt;<br>  &lt;li&gt;項目3<br>      &lt;ul&gt;<br>          &lt;li&gt;項目3-A&lt;/li&gt; <br>      &lt;/ul&gt;<br>  &lt;/li&gt;<br>&lt;/ul&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>這樣的寫法，ul 中的子元素 li 全部變成紅色，但是孫元素的 li (項目3-A)則不受影響，因為他不是子元素(<a href="https://codepen.io/lin-hsienli/pen/pQPppK"><strong>看測試demo</strong></a>)。<br>假如改寫成<strong>子孫選擇器</strong>，所有的 li 元素都會變成紅色的：</p><pre>&lt;style type=&quot;text/css&quot;&gt;<br>  .main-menu li { color: #ff0000; }<br>&lt;/style&gt;</pre><p>● <strong>相鄰選擇器( + )</strong>：可選擇有相同的父元素，緊接在一個元素後的<strong>「第一個」相鄰</strong>兄弟元素(同一層中)，例如下列範例中，只有 h1 的下一個 p 是紅色的，其他第二個之後的 p 仍然是黑色的<strong>(</strong><a href="https://codepen.io/lin-hsienli/pen/XyRZOj"><strong>看測試demo</strong></a><strong>)</strong>。</p><pre>&lt;!DOCTYPE HTML&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;style type=&quot;text/css&quot;&gt;<br>    h1 + p { color: #ff0000; }<br>&lt;/style&gt;<br>&lt;/head&gt;</pre><pre>&lt;body&gt;<br>  &lt;h1&gt;This is a heading.&lt;/h1&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>但是以上這個範例，假如我們改寫成 p + p 的話結果會是什麼？</p><pre>&lt;!DOCTYPE HTML&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;style type=&quot;text/css&quot;&gt;<br>    p + p { color: #ff0000; }<br>&lt;/style&gt;<br>&lt;/head&gt;</pre><pre>&lt;body&gt;<br>  &lt;h1&gt;This is a heading.&lt;/h1&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>因為 p + p 代表的是：有相同的父元素(body)，緊接在一個 p 元素後的<strong>「第一個」相鄰 p 元素。</strong>而這個範例中有五個 p 元素，可得知第二個～第五個 p 元素都會變成紅色的<a href="https://codepen.io/lin-hsienli/pen/maEpGE"><strong>(看測試demo)</strong></a>。<br>這個技巧常用在一個區塊中段落與段落之間的間距<strong>(ex.從第二段開始，與上一個段落保持上方外距)</strong>，可多設想如何運用這個寫法。</p><p>另外，還要介紹一個 css3 新增的選擇器：</p><p>● <strong>間接選擇器( ~ )</strong>：可選擇有相同的父元素，<strong>兄元素「之後所有的」弟元素</strong>，例如剛剛那個範例若改成~選擇器，h1 上面再多加一個 p ，結果是除了h1 上面的那個 p ，底下的 p 全部變成紅色的了<strong>(</strong><a href="https://codepen.io/lin-hsienli/pen/WYjzwb"><strong>看測試demo</strong></a><strong>)</strong>。</p><pre>&lt;!DOCTYPE HTML&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;style type=&quot;text/css&quot;&gt;<br>    h1 ~ p { color: #ff0000; }<br>&lt;/style&gt;<br>&lt;/head&gt;</pre><pre>&lt;body&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;h1&gt;This is a heading.&lt;/h1&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>  &lt;p&gt;This is paragraph.&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>介紹了那麼多 css 選擇器，還有<strong>屬性選擇器</strong>以及<strong>虛擬類別</strong>和<strong>虛擬元素(偽元素)</strong>等許多好用的選擇器留著下篇再繼續介紹。</p><blockquote>先複習一下剛剛說的： <br>&gt;只選擇子元素不選擇孫元素<br>+只選擇相鄰的第一個兄弟元素<br>~可以選擇兄元素之後所有的弟元素</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec19bc5b33a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/css%E9%81%B8%E6%93%87%E5%99%A8%E4%BB%8B%E7%B4%B9-1-ec19bc5b33a">CSS選擇器介紹( 1 )</a> was originally published in <a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A">UI/UX練功坊</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML5 新增的表單元件＆屬性]]></title>
            <link>https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/html5-%E6%96%B0%E5%A2%9E%E7%9A%84%E8%A1%A8%E5%96%AE%E5%85%83%E4%BB%B6-%E5%B1%AC%E6%80%A7-3d7c4f5688a2?source=rss-5ddd7d611b0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d7c4f5688a2</guid>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[input-methods]]></category>
            <dc:creator><![CDATA[Sandy]]></dc:creator>
            <pubDate>Fri, 09 Nov 2018 11:10:28 GMT</pubDate>
            <atom:updated>2018-11-09T11:18:29.007Z</atom:updated>
            <content:encoded><![CDATA[<p>HTML5 新增了不少好用的 input 用法，來看看有哪些</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7tQ-q-GpRJqWEqWHh-Mmtg.jpeg" /></figure><h4>● 新增的 input type</h4><ol><li><strong>搜尋(search)：</strong>用於搜索輸入框，例如站內搜尋或搜尋引擎，外觀與常見的 type=“text” 沒有差別</li></ol><pre>&lt;input type=&quot;search&quot; name=&quot;search&quot; value=&quot;請輸入關鍵字...&quot; /&gt;</pre><p>2. <strong>電子郵件信箱(email)</strong>：輸入的值必須要符合 email 信箱的格式，否則無法提交表單，會自動檢查格式</p><pre>&lt;input type=&quot;email&quot; name=&quot;email&quot; value=&quot;請輸入信箱...&quot; /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YOpoKR6f3jie-zpmFPJTWA.png" /></figure><p>3. <strong>網址(URL)</strong>：輸入的值必須要符合 URL 的格式，否則無法提交表單，會自動檢查格式</p><pre>&lt;input type=&quot;url&quot; name=&quot;url&quot; value=&quot;請輸入網址...&quot; /&gt;</pre><p>4. <strong>電話號碼(tel)</strong>：並沒有限制輸入值的格式(驗證格式要另外自己寫 js )，但在 mobile 端會自動切換為數字輸入的鍵盤</p><pre>&lt;input type=&quot;tel&quot; name=&quot;tel&quot; value=&quot;請輸入手機...&quot; /&gt;</pre><p>5. <strong>數值(number)</strong>：只能輸入數字(※輸入中文 Enter 後會自動消失)，在某些瀏覽器上可以用上下鍵來輸入數字</p><pre>&lt;input type=&quot;number&quot; name=&quot;num&quot; value=&quot;1&quot; /&gt;</pre><p>6. <strong>日期(date)</strong>：默認輸入的日期格式為 YYYY/MM/DD，在某些瀏覽器上會以月曆的形式顯示</p><pre>&lt;input type=&quot;date&quot; name=&quot;birthday&quot; /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*hRaNXih7Lvw8Tu0e2ZINow.png" /></figure><p>※ 雖然 HTML5 有日期選擇器很方便，但考慮到瀏覽器支援度的問題( type date 不支援 Safari 以及 IE 11 以前的版本)，所以可能還是要寫套件，我推薦使用的套件是 <a href="https://fullcalendar.io/">FullCalendar</a> ，再依據需求去改寫 js 的用法</p><p>7. <strong>時間(time)</strong>：默認輸入的時間格式為AM 00:00，在某些瀏覽器上可用上下鍵來輸入時間</p><pre>&lt;input type=&quot;time&quot; name=&quot;time&quot; /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*I7h0hgRTVdzCz0hxXAU8eg.png" /></figure><p>※ HTML5 的時間選擇器一樣有瀏覽器支援度的問題(不支援 Safari 以及 IE 11 以前的版本)，推薦使用的套件是 <a href="https://timepicker.co/options/">jQuery Timepicker</a>，有<a href="http://jonthornton.github.io/jquery-timepicker/">相當多用法</a>，再依據需求去改寫 js</p><p>8. <strong>一定範圍內的數字(range)</strong>：可以用拉動卷軸的方式來輸入大約的數字， IE 9 以前的版本不支援</p><pre>&lt;input type=”range” name=”points” min=”0&quot; max=”10&quot; /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*UbIqoK0sONGGJ2fGZasF-w.png" /></figure><p>9. <strong>顏色(color)</strong>：可以用RGB色盤來選取色碼(格式#000000)，但 Safari 9.1 以前與 IE 11 以前的版本不支援</p><pre>&lt;input type=”color” name=”color” value=”#ff0000&quot; /&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*Dh-BE00Swm36eItIPKhWFg.png" /></figure><p>最後，若想了解所有 input type 的用法，<a href="https://www.w3schools.com/tags/att_input_type.asp">w3schools.com</a> 有完整的介紹與Demo 可以看，這是很常用的標籤必須要熟練用法</p><h4>● 讓表單變好用的 HTML5 新屬性</h4><ol><li><strong>autofocus</strong>：開啟網頁時，自動將游標停在指定的表單元件上(輸入框 focus 狀態默認為藍色的外光暈)，<strong>每個頁面只能設定一個 autofocus 屬性</strong></li></ol><pre>&lt;input type=”text” name=”name” autofocus /&gt;</pre><p>2. <strong>autocomplete</strong>：會依據以前輸入的內容自動輸入，<strong>預設值為“ on ”</strong>，若要關閉自動輸入功能，指定為“ off ”即可。若設定在&lt;form&gt;標籤，則所有表單中的元件都適用此設定</p><pre>&lt;input type=”search” name=”example” autocomplete=”off” /&gt;</pre><p>3. <strong>placeholder</strong>：設定後在輸入元件會顯示灰色的提示文字，幫助使用者輸入(例如提示-規定輸入的格式等)，開始輸入後就會以輸入的資料(黑色文字)取代原本的提示文字了</p><pre>&lt;input type=”tel” name=”tel” placeholder=”0988-123456” /&gt;</pre><p>4. <strong>required</strong>：可將表單元件設定為「必填」欄位，若未選填就按下提交按鈕，就會跳出提示文字，要求一定要輸入資料才能送出</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/478/1*1Cskg_OUUWWhDaiaQwlYlQ.png" /></figure><p>※ 若需要做更進一步的表單驗證格式，可使用 <a href="https://jqueryvalidation.org/">jQuery Validation Plugin</a>，有相當多驗證格式可以使用</p><p>5. <strong>min / max / step</strong>：可用在數值(number)、日期(date)、時間(time)的輸入，分別規定最小值(min)、最大值(max)和遞增值(step)，以數值為範例如下列寫法：</p><pre>&lt;input type=”number” min=”1&quot; max=”10&quot; step=”0.5&quot; /&gt;</pre><p>假如說是要限制可以輸入的字數，要用的屬性則是 minlength 與 maxlength， 但仍然要注意瀏覽器的支援度，否則還是寫 js 驗證比較保險</p><pre>&lt;input type=&quot;text&quot; name=&quot;username&quot; minlength=&quot;3&quot; maxlength=&quot;10&quot; /&gt;</pre><blockquote>總結：雖然各家瀏覽器對於 HTML5 新屬性的支援度不一，但假如合乎目前開發需求的版本，還是可以使用上述這些好用的功能</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d7c4f5688a2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/html5-%E6%96%B0%E5%A2%9E%E7%9A%84%E8%A1%A8%E5%96%AE%E5%85%83%E4%BB%B6-%E5%B1%AC%E6%80%A7-3d7c4f5688a2">HTML5 新增的表單元件＆屬性</a> was originally published in <a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A">UI/UX練功坊</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[form表單中的get與post有什麼差別？]]></title>
            <link>https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/form%E8%A1%A8%E5%96%AE%E4%B8%AD%E7%9A%84get%E8%88%87post%E6%9C%89%E4%BB%80%E9%BA%BC%E5%B7%AE%E5%88%A5-d2a04845769a?source=rss-5ddd7d611b0c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d2a04845769a</guid>
            <category><![CDATA[post]]></category>
            <category><![CDATA[get]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[methods]]></category>
            <dc:creator><![CDATA[Sandy]]></dc:creator>
            <pubDate>Fri, 09 Nov 2018 07:18:00 GMT</pubDate>
            <atom:updated>2018-11-09T07:18:00.027Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>重點整理引用自 <a href="https://blog.toright.com/">Soul &amp; Shell Blog</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CS7XfUmCif2Y1Jg769WYlw.jpeg" /></figure><p>表單&lt;form&gt;~&lt;/form&gt;中的屬性 action 是資料接收端的路徑，屬性 method 則是規定用於發送 form-data 的 HTTP 方法，可分為〝get〞與〝post〞兩種：</p><pre>&lt;form id=&quot;myform&quot; action=&quot;form_action.asp&quot; method=&quot;post&quot;&gt;<br>  &lt;p&gt;First name: &lt;input type=&quot;text&quot; name=&quot;fname&quot; /&gt;&lt;/p&gt;<br>  &lt;p&gt;Last name: &lt;input type=&quot;text&quot; name=&quot;lname&quot; /&gt;&lt;/p&gt;<br>  &lt;input type=&quot;submit&quot; value=&quot;Submit&quot; /&gt;<br>&lt;/form&gt;</pre><p>舉個例子來說，假如 HTTP 是我們生活中寄信的機制，HTTP Method 就是寄信的方式。我們姑且把信封外的內容稱為 http-header，信封內的書信稱為message-body，來看看這兩種方式有什麼差別：</p><p>● <strong>get</strong>：類似<strong>明信片</strong>一樣，我們可以把要傳遞的資訊直接寫在(http-header)上面，郵資比較便宜，但是信件的安全度比較低，容易被其他人看到內容。</p><p>使用 get 時，瀏覽器會自動將表單要傳送的資料轉為 Query String 加在我們要寄送的地址(URL)後面進行連線，所以在表單提交(Submit)後，我們可以看到<strong>瀏覽器的網址改變</strong>，例如<strong>〝https://medium.com/?id=010101〞</strong></p><p>HTTP GET Method 是不允許在 message-body 中傳遞資料的，因為 get就是要「取得」資料的意思。但是從瀏覽器的網址就可以看見表單要傳送的資料，若是要傳送密碼豈不是一覽無遺……所以會有資安方面的顧慮。</p><p>● <strong>post</strong>：類似<strong>信封+信紙</strong>一樣，我們必須把寄送地址(URL)寫在信封上，另外將要傳送的資料寫在信紙(message-body)上，將信紙放入信封中，再交給郵差寄送，雖然郵資比較貴，但是信件的安全度比較高。</p><p>用 post 這個方法，資料傳送後<strong>瀏覽器的網址沒有變化</strong>。因為 post 是將表單資料放在 message-body 中進行傳送，在不偷看封包的情況下，是相對比較安全的作法。所以許多網頁設計師對於表單中 method 的用法才會有這些印象：〝post 可以傳送比較多的資料〞、〝表單傳送檔案的時候要使用 post〞、〝post 比 get 安全〞。</p><blockquote>以上內容，整理引用自：<br>SJ撰寫的<a href="https://blog.toright.com/posts/1203/%E6%B7%BA%E8%AB%87-http-method%EF%BC%9A%E8%A1%A8%E5%96%AE%E4%B8%AD%E7%9A%84-get-%E8%88%87-post-%E6%9C%89%E4%BB%80%E9%BA%BC%E5%B7%AE%E5%88%A5%EF%BC%9F.html">淺談 HTTP Method：表單中的 GET 與 POST 有什麼差別？</a><br>若有不適當之處請告知，馬上將文章刪除，謝謝</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d2a04845769a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A/form%E8%A1%A8%E5%96%AE%E4%B8%AD%E7%9A%84get%E8%88%87post%E6%9C%89%E4%BB%80%E9%BA%BC%E5%B7%AE%E5%88%A5-d2a04845769a">form表單中的get與post有什麼差別？</a> was originally published in <a href="https://medium.com/ui-ux%E7%B7%B4%E5%8A%9F%E5%9D%8A">UI/UX練功坊</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>