<?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>css &#8211; 小豬日常</title>
	<atom:link href="https://piglife.tw/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>https://piglife.tw</link>
	<description>Hello World，一個紀錄生活與學習的地方</description>
	<lastBuildDate>Fri, 19 Dec 2025 05:30:37 +0000</lastBuildDate>
	<language>zh-TW</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://piglife.tw/wp-content/uploads/2017/10/cropped-logo-1-32x32.png</url>
	<title>css &#8211; 小豬日常</title>
	<link>https://piglife.tw</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>自訂 Gutenberg 編輯器中文章區塊最大寬度的實作說明</title>
		<link>https://piglife.tw/technical-notes/custom-gutenberg-editor-width-2/</link>
					<comments>https://piglife.tw/technical-notes/custom-gutenberg-editor-width-2/#respond</comments>
		
		<dc:creator><![CDATA[小豬]]></dc:creator>
		<pubDate>Thu, 18 Dec 2025 22:50:25 +0000</pubDate>
				<category><![CDATA[技術筆記]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[Gutenberg]]></category>
		<category><![CDATA[WordPress]]></category>
		<guid isPermaLink="false">https://piglife.tw/technical-notes/custom-gutenberg-editor-width-2/</guid>

					<description><![CDATA[介紹如何透過 WordPress 後台掛載自訂 CSS，限制 Gutenberg 編輯器中文章區塊的...]]></description>
										<content:encoded><![CDATA[<h2 class="wp-block-heading">前言</h2>
<p>在使用 WordPress 的 Gutenberg 編輯器時，預設的區塊寬度可能不符合特定網站設計需求，尤其是針對文章（post）類型。這段程式碼示範如何透過後台樣式調整，限制文章區塊的最大寬度，讓編輯介面更貼近前端顯示效果，適合想優化編輯體驗的開發者與自學者。</p>
<h2 class="wp-block-heading">為什麼要調整 Gutenberg 編輯器的區塊寬度？</h2>
<p>Gutenberg 編輯器的區塊寬度預設較寬，可能導致編輯時排版與前端顯示不一致，影響內容編輯的直觀感受。透過限制最大寬度，可以讓編輯時的視覺效果更接近實際網站呈現，減少排版錯誤。</p>
<h2 class="wp-block-heading">程式碼解析</h2>
<h3 class="wp-block-heading">1. 透過 admin_head 動作掛載自訂樣式</h3>
<pre><code class="lang-php language-php php">add_action( &#039;admin_head&#039;, &#039;custom_post_gutenberg_editor_width&#039; );</code></pre>
<p>這行程式碼將自訂函式掛載到 WordPress 後台的 head 區塊，確保樣式只在後台生效。</p>
<h3 class="wp-block-heading">2. 目標限定為文章(post)類型的區塊</h3>
<pre><code class="lang-css language-css css">.post-type-post .wp-block {
    max-width: 600px !important;
}</code></pre>
<p>這段 CSS 限制所有文章類型的區塊最大寬度為 600px，避免編輯器區塊過寬。</p>
<h3 class="wp-block-heading">3. 調整 &#8220;wide&#8221; 對齊方式的寬度</h3>
<pre><code class="lang-css language-css css">.post-type-post .wp-block[data-align=&quot;wide&quot;] {
    max-width: 600px !important;
}</code></pre>
<p>將 &#8220;wide&#8221; 對齊的區塊同樣限制在 600px，避免因預設寬度過寬而影響排版。</p>
<h3 class="wp-block-heading">4. 保留 &#8220;full&#8221; 對齊的全寬效果</h3>
<pre><code class="lang-css language-css css">.post-type-post .wp-block[data-align=&quot;full&quot;] {
    max-width: none !important;
}</code></pre>
<p>讓 &#8220;full&#8221; 對齊的區塊維持編輯器全寬，符合使用者預期的全屏展示。</p>
<h2 class="wp-block-heading">實務應用與延伸</h2>
<ul>
<li>可依需求調整 max-width 數值，配合網站前端設計寬度。</li>
<li>若需針對其他自訂文章類型，也可複製此函式並修改 .post-type-post 選擇器。</li>
<li>若想更細緻控制不同區塊類型寬度，可增加更多 CSS 選擇器與規則。</li>
</ul>
<h2 class="wp-block-heading">常見問題與注意事項</h2>
<ul>
<li>使用 !important 是為了覆蓋 Gutenberg 預設樣式，避免無效。</li>
<li>此方法只影響後台編輯器，不會改變前端顯示。</li>
<li>若有快取或 CSS 優先權問題，請清除快取或調整掛載優先順序。</li>
</ul>
<h2 class="wp-block-heading">完整程式碼</h2>
<pre><code class="lang-php language-php php">&lt;?php
function custom_post_gutenberg_editor_width() {
    echo &#039;
&lt;style&gt;
        /* Target ONLY the standard &quot;post&quot; post type in the editor */
        .post-type-post .wp-block {
            max-width: 600px !important; 
        }

        /* Optionally, set the &quot;wide&quot; alignment to the same narrow width */
        .post-type-post .wp-block[data-align=&quot;wide&quot;] {
            max-width: 600px !important; 
        }

        /* Ensure &quot;full&quot; alignment still goes full width of the editor screen */
        .post-type-post .wp-block[data-align=&quot;full&quot;] {
            max-width: none !important;
        }
    &lt;/style&gt;&#039;;
}
add_action( &#039;admin_head&#039;, &#039;custom_post_gutenberg_editor_width&#039; );</code></pre>]]></content:encoded>
					
					<wfw:commentRss>https://piglife.tw/technical-notes/custom-gutenberg-editor-width-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WordPress 自定義 CSS 與 JS 檔案載入實作筆記</title>
		<link>https://piglife.tw/technical-notes/wordpress-custom-css-js/</link>
					<comments>https://piglife.tw/technical-notes/wordpress-custom-css-js/#respond</comments>
		
		<dc:creator><![CDATA[小豬]]></dc:creator>
		<pubDate>Sun, 18 Dec 2022 08:47:22 +0000</pubDate>
				<category><![CDATA[技術筆記]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[functions.php]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp_enqueue_script]]></category>
		<category><![CDATA[wp_enqueue_style]]></category>
		<guid isPermaLink="false">https://piglife.tw/?p=407</guid>

					<description><![CDATA[說明如何在 WordPress 主題的 functions.php 中載入自定義 CSS 和 JS ...]]></description>
										<content:encoded><![CDATA[<h2 class="wp-block-heading">前言</h2>
<p>在開發 WordPress 網站時，常常需要加入自定義的 CSS 和 JavaScript 來調整樣式或增加互動效果。直接在主題的 functions.php 檔案中註冊並載入這些檔案，是一種方便且易於維護的做法，適合本地開發與版本控管。</p>
<h2 class="wp-block-heading">在 functions.php 中載入自定義 CSS 和 JS</h2>
<p>WordPress 提供了 wp_enqueue_style 和 wp_enqueue_script 兩個函式，分別用來載入 CSS 和 JS 檔案。通常會將這些載入動作放在一個自訂函式中，並透過 add_action 掛載到 wp_enqueue_scripts 鉤子。</p>
<p>以下是範例程式碼片段：</p>
<pre><code class="lang-php language-php php">add_action( &#039;wp_enqueue_scripts&#039;, &#039;custom_style_scripts&#039; );

/**
 * Enqueue scripts and styles.
 */
function custom_style_scripts() {
    // CSS 檔案放在子主題的 css 資料夾中
    wp_enqueue_style( &#039;main_css&#039;, get_stylesheet_directory_uri() . &#039;/css/main.css&#039; );

    // JS 檔案放在子主題的 js 資料夾中，依賴 jQuery，並放置於頁面底部
    wp_enqueue_script( &#039;main_js&#039;, get_stylesheet_directory_uri() . &#039;/js/main.js&#039;, array(&#039;jquery&#039;), false, true );
}</code></pre>
<h2 class="wp-block-heading">實務應用與注意事項</h2>
<ul>
<li>建議將 CSS 和 JS 分別放在子主題的 css 和 js 資料夾中，方便管理與版本控制。</li>
<li>在本地開發時，可以搭配 Gulp 或其他前端工具編譯 SCSS，並自動更新這些檔案。</li>
<li>wp_enqueue_script 的最後一個參數設為 true，確保 JS 載入於頁面底部，提升頁面載入效能。</li>
<li>若有多個腳本或樣式檔案，依照需求分別註冊並載入，避免重複或衝突。</li>
</ul>
<h2 class="wp-block-heading">相關官方文件</h2>
<ul>
<li><a href="https://developer.wordpress.org/reference/functions/wp_enqueue_script/" target="_blank" rel="noopener">wp_enqueue_script</a></li>
<li><a href="https://developer.wordpress.org/reference/functions/wp_enqueue_style/" target="_blank" rel="noopener">wp_enqueue_style</a></li>
</ul>
<h2 class="wp-block-heading">完整程式碼</h2>
<pre><code class="lang-text language-text text">add_action( &#039;wp_enqueue_scripts&#039;, &#039;custom_style_scripts&#039; );

/**
 * Enqueue scripts and styles.
 */
function custom_style_scripts() {
    //目錄可自行在子主題下面建立路徑像是css都放到css資料夾中，js就放到js資料夾中
    //載入CSS
    wp_enqueue_style( &#039;main_css&#039;, get_stylesheet_directory_uri() . &#039;/css/main.css&#039; );
    //載入JS
    wp_enqueue_script( &#039;main_js&#039;, get_stylesheet_directory_uri() . &#039;/js/main.js&#039;, array(&#039;jquery&#039;), false, true );
}</code></pre>]]></content:encoded>
					
					<wfw:commentRss>https://piglife.tw/technical-notes/wordpress-custom-css-js/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>去除 HTML img 標籤多餘空格白線的技術筆記</title>
		<link>https://piglife.tw/technical-notes/remove-html-img-white-space/</link>
					<comments>https://piglife.tw/technical-notes/remove-html-img-white-space/#respond</comments>
		
		<dc:creator><![CDATA[小豬]]></dc:creator>
		<pubDate>Tue, 21 Nov 2017 08:15:52 +0000</pubDate>
				<category><![CDATA[技術筆記]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[display-block]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[img標籤]]></category>
		<category><![CDATA[圖片拼接]]></category>
		<category><![CDATA[空白白線]]></category>
		<guid isPermaLink="false">https://piglife.tw/?p=282</guid>

					<description><![CDATA[說明如何解決 HTML img 標籤在並排時產生的多餘空白白線問題，透過設定 display:blo...]]></description>
										<content:encoded><![CDATA[<h2 class="wp-block-heading">前言</h2>
<p>在網頁設計或 EDM 製作中，常會遇到將多張圖片並排時，中間出現不必要的空白白線問題。這種白線通常是因為圖片元素的默認行內行為導致的空格，對於需要精確拼接圖片的場景非常困擾。</p>
<h2 class="wp-block-heading">問題說明</h2>
<p>當兩個 <code>&lt;img&gt;</code> 標籤並排時，瀏覽器會將它們視為行內元素，並在圖片間插入空白字元，導致中間出現白線。這在視覺上會破壞圖片的連續性。</p>
<h2 class="wp-block-heading">解決方案</h2>
<p>最簡單有效的方法是將 <code>&lt;img&gt;</code> 標籤的 CSS 屬性 <code>display</code> 設為 <code>block</code>，使圖片變成區塊元素，消除行內元素間的空白。</p>
<pre><code class="lang-css language-css css">img {
  display: block;
}</code></pre>
<p>這樣設定後，圖片間的空白白線就會消失，圖片可以無縫拼接。</p>
<h2 class="wp-block-heading">實際應用</h2>
<p>在實務中，只要在 CSS 中加入上述設定，或直接在圖片元素上加上 <code>style=&quot;display:block;&quot;</code>，即可快速解決問題。這對於 EDM 或需要精準排版的網頁設計非常實用。</p>
<h2 class="wp-block-heading">常見坑</h2>
<ul>
<li>直接刪除 HTML 中的空白字元不一定有效，因為瀏覽器仍會將行內元素間的空白視為間距。</li>
<li>使用 <code>float</code> 或 <code>flex</code> 也能解決，但相對複雜且可能影響其他排版。</li>
</ul>
<h2 class="wp-block-heading">完整程式碼</h2>
<pre><code class="lang-text language-text text">&lt;img src=&quot;圖片路徑&quot; style=&quot;display:block;&quot; /&gt;</code></pre>]]></content:encoded>
					
					<wfw:commentRss>https://piglife.tw/technical-notes/remove-html-img-white-space/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
