Sass 混合

混合讓我們可以在架構的各個部分重複使用程式碼。Foundation 包含用於清除浮動、可見性、圖示、形狀等混合。

匯入

Foundation 的 Sass 混合全部儲存在一個檔案中:scss/util/_mixins.scss。若要在 Sass 中匯入,請使用這行程式碼

@import 'util/mixins';

注意:使用 ZURB 堆疊基本範本 Starter Projects 時,這些混合會預設包含。

一般混合

Foundation 包含一些實用的 Sass 混合,用於快速建立樣式或延伸和真正自訂現有的元件。以下是可用的混合清單

原型製作工具程式混入

使用 Foundation 的原型製作工具程式混入快速製作版面和 UI 原型。這些混入非常適合將您的草圖和模型轉換為高保真編碼原型,而且速度超快。 深入了解原型製作工具程式

以下是可用混入的清單


Sass 參考

變數

您可以在專案的 設定檔 中使用這些 Sass 變數自訂此元件的預設樣式。

名稱類型預設值說明
$prototype-arrow-directions 對應 向下
向上
向右
向左

包含所有 arrow 方向的對應

$prototype-arrow-size 數字 0.4375rem

箭頭寬度,預設為 0.4375rem

$prototype-arrow-color 顏色 $black

箭頭顏色,預設為 $black

$prototype-border-box-breakpoints 布林值 $global-prototype-breakpoints

邊框方塊的回應式中斷點。

$prototype-border-none-breakpoints 布林值 $global-prototype-breakpoints

無邊框的回應式中斷點。

$prototype-bordered-breakpoints 布林值 $global-prototype-breakpoints

有邊框工具程式的回應式中斷點。

$prototype-border-width 數字 rem-calc(1)

prototype-border-width 的預設值

$prototype-border-type 字串 實心

prototype-border-type 的預設值

$prototype-border-color 顏色 $medium-gray

prototype-border-color 的預設值預設為 medium-gray

$prototype-display-breakpoints 布林值 $global-prototype-breakpoints

顯示類別的回應式中斷點

$prototype-display 對應 inline
inline-block
block
table
table-cell

包含所有 display 類別的地圖

$prototype-font-breakpoints 布林值 $global-prototype-breakpoints

字型樣式類型的回應式中斷點

$prototype-wide-letter-spacing 數字 rem-calc(4)

.font-wide 的字元間距

$prototype-font-normal 數字 $global-weight-normal

.font-normal 的預設粗細,預設為 global-weight-normal

$prototype-font-bold 數字 $global-weight-bold

.font-bold 的預設粗細,預設為 global-weight-bold

$prototype-list-breakpoints 布林值 $global-prototype-breakpoints

列表樣式類型的回應式中斷點

$prototype-style-type-unordered 對應 disc
circle
square

包含所有 style-type-unordered 類別的地圖

$prototype-style-type-ordered 對應 decimal
lower-alpha
lower-latin
lower-roman
upper-alpha
upper-latin
upper-roman

包含所有 style-type-ordered 類別的地圖

$prototype-overflow-breakpoints 布林值 $global-prototype-breakpoints

溢位輔助類別的回應式中斷點

$prototype-overflow 對應 visible
hidden
scroll

包含所有 overflow 類別的地圖

$prototype-position-breakpoints 布林值 $global-prototype-breakpoints

位置輔助類別的回應式中斷點

$prototype-position 對應 static
relative
absolute
fixed

包含所有 position 類別的地圖

$prototype-position-z-index 數字 975

固定定位的 z-index

$prototype-rounded-breakpoints 布林值 $global-prototype-breakpoints

圓角實用工具的回應式中斷點。

$prototype-border-radius 數字 rem-calc(3)

prototype-border-radius 的預設值

$prototype-separator-breakpoints 布林值 $global-prototype-breakpoints

分隔線的回應式中斷點。

$prototype-separator-align 字串 center

分隔線的預設對齊方式。

$prototype-separator-height 數字 rem-calc(2)

分隔線的高度。

$prototype-separator-width 數字 3rem

分隔線的寬度。

$prototype-separator-background 顏色 $primary-color

分隔線的預設顏色。

$prototype-separator-margin-top 數字 $global-margin

分隔線的上邊界。

$prototype-shadow-breakpoints 布林值 $global-prototype-breakpoints

陰影實用程式回應式中斷點。

$prototype-box-shadow 數字 0 2px 5px 0 rgba(0, 0, 0, 0.16), 0 2px 10px 0 rgba(0, 0, 0, 0.12)

prototype-box-shadow 的預設值

$prototype-sizing-breakpoints 布林值 $global-prototype-breakpoints

間距類別(邊界和內距)的回應式中斷點

$prototype-sizing 對應 寬度
高度

包含所有 sizing 類別的地圖

$prototype-sizes 對應 25: 25%
50: 50%
75: 75%
100: 100%

包含所有大小的地圖。

$prototype-spacing-breakpoints 布林值 $global-prototype-breakpoints

間距類別(邊界和內距)的回應式中斷點

$prototype-spacers-count 數字 3

預設的間距計數(邊界和內距)

$prototype-decoration-breakpoints 布林值 $global-prototype-breakpoints

文字裝飾類別的回應式中斷點

$prototype-text-decoration 對應 上劃線
底線
刪除線

包含所有 text-decoration 類別的地圖

$prototype-transformation-breakpoints 布林值 $global-prototype-breakpoints

文字轉換類別的回應式中斷點

$prototype-text-transformation 對應 小寫
大寫
首字母大寫

包含所有 text-transformation 類別的地圖

$prototype-utilities-breakpoints 布林值 $global-prototype-breakpoints

文字實用程式的回應式中斷點

$prototype-text-overflow 字串 省略號

text-overflow 變數的預設值


混合

我們使用這些混合來建立此元件的最終 CSS 輸出。您可以自行使用混合,從我們的元件中建立自己的類別結構。

inner-side-shadow

@include inner-side-shadow($side, $size, $color);

僅為一側建立內部方框陰影

參數類型預設值說明
$side 關鍵字

陰影應顯示的一側。可以是 topleftrightbottom

$size 數字

目標側的寬度。

$color 顏色

陰影的顏色。


css-triangle

@include css-triangle($triangle-size, $triangle-color, $triangle-direction);

建立一個 CSS 三角形,可用於下拉式箭頭、下拉式提示等。在 &::before&::after 選擇器內使用此混合,將三角形附加到現有元素。

參數類型預設值說明
$triangle-size 數字

三角形的寬度。

$triangle-color 顏色

三角形的顏色。

$triangle-direction 關鍵字

三角形指向的方向。可以是 uprightdownleft


hamburger

@include hamburger($color, $color-hover, $width, $height, $weight, $bars);

建立一個具有設定寬度、高度、長條數和顏色的選單圖示。此混合使用圖示的高度和長條的粗細來決定間距。

參數類型預設值說明
$color 顏色 $black

用於圖示的顏色。

$color-hover 顏色 $dark-gray

當將滑鼠游標移到圖示上時使用的顏色。

$width 數字 20px

圖示的寬度。

$height 數字 16px

圖示的高度。

$weight 數字 2px

圖示中個別長條的高度。

$bars 數字 3

圖示中長條的數量。


background-triangle

@include background-triangle($color);

將向下三角形新增為元素的背景圖片。圖片格式為 SVG,方便變更顏色。由於 Internet Explorer 不支援編碼 SVG 作為背景圖片,因此也包含 PNG 備用方案。有兩個 PNG 備用方案:黑色三角形和白色三角形。所使用的方案取決於輸入顏色的明度。

參數類型預設值說明
$color 顏色 $black

三角形要使用的顏色。


clearfix

@include clearfix;

套用 Nicolas Gallagher 推廣的微型 clearfix 技巧。如果容器中的所有子元素都已浮動,請在容器中包含這個混合,以提供容器適當的高度。clearfix 已擴充特定樣式,以防止在 flexbox 環境中出現邊框

深入了解: 微型 Clearfix 技巧


auto-width

@include auto-width($max, $elem);

新增 CSS 以進行「數量查詢」選擇器,根據容器內有多少元素自動調整元素大小。

深入了解: CSS 的數量查詢

參數類型預設值說明
$max 數字

要偵測的最大項目數。這個數字越大,需要涵蓋每個項目數的 CSS 就越多。

$elem 關鍵字 li

用於同層選擇器的標籤。


disable-mouse-outline

@include disable-mouse-outline;

偵測到滑鼠輸入時,移除元素周圍的焦點環。


element-invisible

@include element-invisible($enforce);

讓元素在視覺上隱藏,但仍可使用鍵盤和輔助裝置存取。

深入了解: 隱藏內容以利於存取

參數類型預設值說明
$enforce 布林值

如果為 true,在套用的屬性上使用 !important


element-invisible-off

@include element-invisible-off($enforce);

反轉 element-invisible() 混合產生的 CSS 輸出。

參數類型預設值說明
$enforce 布林值

如果為 true,在套用的屬性上使用 !important


vertical-center

@include vertical-center;

垂直置中元素在其第一個非靜態父元素內,

深入了解: 使用 Sass 置中


horizontal-center

@include horizontal-center;

水平置中元素在其第一個非靜態父元素內,

深入了解: 使用 Sass 置中


absolute-center

@include absolute-center;

絕對置中元素在其第一個非靜態父元素內,

深入了解: 使用 Sass 置中


border-box

@include border-box;

邊框方塊輔助工具


border-none

@include border-none;

無邊框輔助工具


bordered

@include bordered($width, $type, $color);

有邊框輔助工具:預設為在元素上加入細邊框。

參數類型預設值說明
$width 數字 $prototype-border-width

邊框寬度

$type 字串 $prototype-border-type

邊框類型

$color 顏色 $prototype-border-color

邊框顏色


box

@include box($width, $height, $circle);

方塊混合:輕鬆建立正方形、長方形或圓形

參數類型預設值說明
$width 數字

方塊寬度

$height 數字 $width

方塊高度,預設為 $width,可輕鬆建立正方形

$circle 布林值 false

將方塊設為圓形,預設為 false


display

@include display($display);

顯示類別,預設透過地圖 $prototype-display 呈現

參數類型預設值說明
$display 字串

顯示類別


font-wide

@include font-wide($letter-spacing);

字體寬間距!

參數類型預設值說明
$letter-spacing 數字 $prototype-wide-letter-spacing

字體寬間距


font-normal

@include font-normal($weight);

字體粗細正常,預設值透過 global-weight-normal 呈現

參數類型預設值說明
$weight 數字 $prototype-font-normal

字體粗細(正常)


font-bold

@include font-bold($weight);

字體粗細粗體,預設值透過 global-weight-bold 呈現

參數類型預設值說明
$weight 數字 $prototype-font-bold

字體粗細(粗體)


font-italic

@include font-italic;

字體樣式斜體


style-type-unordered

@include style-type-unordered($style-type-unordered);

無序清單的樣式類型,預設透過地圖 $prototype-style-type-unordered 呈現

參數類型預設值說明
$style-type-unordered 字串

無序清單的樣式類型


style-type-ordered

@include style-type-ordered($style-type-ordered);

有序清單的樣式類型,預設透過地圖 $prototype-style-type-ordered 呈現

參數類型預設值說明
$style-type-ordered 字串

有序清單的樣式類型


overflow

@include overflow($overflow);

溢位類別,預設透過地圖 $prototype-overflow 呈現

參數類型預設值說明
$overflow 字串

溢位類別


overflow-x

@include overflow-x($overflow);

水平軸的溢位類別,預設透過地圖 $prototype-overflow 呈現

參數類型預設值說明
$overflow 字串

溢位類別(水平軸)


overflow-y

@include overflow-y($overflow);

垂直軸的溢位類別,預設透過地圖 $prototype-overflow 呈現

參數類型預設值說明
$overflow 字串

溢位類別(垂直軸)


position

@include position($position, $top, $right, $bottom, $left);

位置類別,預設透過地圖 $prototype-position 呈現,其中所有偏移值都乘以 $global-position,預設等於 1rem

參數類型預設值說明
$position 字串

位置類別,可以是 staticrelativeabsolutefixed

$top 數字 null

頂部偏移量

$right 數字 null

右側偏移量

$bottom 數字 null

底部偏移量

$left 數字 null

左側偏移量


position-fixed-top

@include position-fixed-top($z-index);

固定定位在頂部角落

參數類型預設值說明
$z-index 數字 $prototype-position-z-index

position-fixed-top 的 z-index


position-fixed-bottom

@include position-fixed-bottom($z-index);

固定定位在底部角落

參數類型預設值說明
$z-index 數字 $prototype-position-z-index

position-fixed-bottom 的 z-index


rotate

@include rotate($deg);

旋轉 Mixin:將元素旋轉到某個角度

參數類型預設值說明
$deg 數字

旋轉角度


rotateX

@include rotateX($deg);

RotateX Mixin:將元素在 X 軸上旋轉到某個角度

參數類型預設值說明
$deg 數字

旋轉角度


rotateY

@include rotateY($deg);

RotateY Mixin:將元素在 Y 軸上旋轉到某個角度

參數類型預設值說明
$deg 數字

旋轉角度


rotateZ

@include rotateZ($deg);

RotateZ Mixin:將元素在 Z 軸上旋轉到某個角度

參數類型預設值說明
$deg 數字

旋轉角度


border-radius

@include border-radius($radius);

圓角實用程式(所有角落):預設將圓角(所有角落)新增到元素。

參數類型預設值說明
$radius 數字 $prototype-border-radius

邊框圓角(所有角落)


border-rounded

@include border-rounded;

圓角正方形實用程式或長方形實用程式(所有角落):預設將所有角落圓角化,形成藥丸形狀。


separator

@include separator($align, $height, $width, $background, $top);

標題分隔線實用程式,主要用於設定區段標題的樣式

參數類型預設值說明
$align 字串 $prototype-separator-align

分隔線對齊

$height 數字 $prototype-separator-height

寬度

$width 數字 $prototype-separator-width

高度

$background 顏色 $prototype-separator-background

背景

$top 數字 $prototype-separator-margin-top

上邊距


shadow

@include shadow($shadow);

陰影實用程式:預設將淺色方框陰影新增到元素。

參數類型預設值說明
$shadow 數字 $prototype-box-shadow

元件的方框陰影


max-width-100

@include max-width-100;

最大寬度 100 實用程式。


max-height-100

@include max-height-100;

最大高度 100 實用程式。


margin

@include margin($top, $right, $bottom, $left);

邊界輔助 mixin,所有值都乘以 $global-margin,預設值為 1rem

參數類型預設值說明
$top 數字 null

上邊距

$right 數字 null

右側邊界

$bottom 數字 null

底部邊界

$left 數字 null

左側邊界


padding

@include padding($top, $right, $bottom, $left);

內邊距輔助 mixin,所有值都乘以 $global-padding,預設值為 1rem

參數類型預設值說明
$top 數字 null

上內邊距

$right 數字 null

右側內邊距

$bottom 數字 null

內距下

$left 數字 null

內距左


margin-direction

@include margin-direction($dir, $spacer);

特定方向屬性的邊界類別

參數類型預設值說明
$dir 字串

方向

$spacer 數字

間隔


padding-direction

@include padding-direction($dir, $spacer);

特定方向屬性的內距類別

參數類型預設值說明
$dir 字串

方向

$spacer 數字

間隔


text-decoration

@include text-decoration($decoration);

文字裝飾,預設透過地圖 $prototype-text-decoration 產生

參數類型預設值說明
$decoration 字串

文字裝飾


text-transform

@include text-transform($transformation);

文字轉換,預設透過地圖 $prototype-text-transformation 產生

參數類型預設值說明
$transformation 字串

文字轉換


text-hide

@include text-hide;

影像替換工具程式。text-hide


text-truncate

@include text-truncate($overflow);

截斷文字,預設為省略號。

參數類型預設值說明
$overflow 字串 $prototype-text-overflow

截斷文字


text-nowrap

@include text-nowrap;

不換行文字。text-nowrap


text-wrap

@include text-wrap;

換行文字。text-wrap


first

@include first($num) { }

從第一個到 $num 選取所有子項。

參數類型預設值說明
$num 數字

所有子項中前 n 個數字


first-child

@include first-child { }

選取第一個精確的子項


last

@include last($num) { }

從最後一個到 $num 選取所有子項。

參數類型預設值說明
$num 數字

所有子項中後 n 個數字


last-child

@include last-child { }

選取最後一個精確的子項


every

@include every($num) { }

$num 個選取一個子項。

參數類型預設值說明
$num 數字

所有子項中每 n 個數字


first-last

@include first-last { }

僅選取第一個和最後一個子項。


after-first

@include after-first($num) { }

從第一個到 $num 選取所有子項。

參數類型預設值說明
$num 數字

所有子項中從第一個開始的後 n 個數字


from-last

@include from-last($num) { }

從最後一個開始,選取 $num 個子項。

參數類型預設值說明
$num 數字

所有子項中從最後一個開始的前 n 個數字


from-first-last

@include from-first-last($num) { }

從第一個開始選取 $num 個子項,從最後一個開始選取 $num 個子項。

參數類型預設值說明
$num 數字

從第一個和最後一個開始的 n 個數字


all-but

@include all-but($num) { }

選取所有子項,但排除 $num 個。

參數類型預設值說明
$num 數字

應從所有其他子項中排除的 n 個數字


all-but-first-last

@include all-but-first-last($num) { }

選取從第一個開始的 $num 個和從最後一個開始的 $num 個之間的所有子項。

參數類型預設值說明
$num 數字

從所有其他子項中排除從第一個和最後一個開始的 n 個數字


unique

@include unique { }

如果子元素是唯一的,則只會選取它。這表示如果至少有 2 個子元素,則不會套用樣式。


not-unique

@include not-unique { }

如果子元素不是唯一的,則只會選取它們。這表示如果至少有 2 個子元素,則會套用樣式。


between

@include between($first, $last) { }

選取介於 $first$last 之間的所有子元素。

參數類型預設值說明
$first 數字

第一個 nth 數字

$last 數字

最後一個 nth 數字


even

@include even { }

選取所有偶數子元素。


even-between

@include even-between($first, $last) { }

選取介於 $first$last 之間的所有偶數子元素。

參數類型預設值說明
$first 數字

第一個 nth 數字

$last 數字

最後一個 nth 數字


odd

@include odd { }

選取所有奇數子元素。


odd-between

@include odd-between($first, $last) { }

選取介於 $first$last 之間的所有奇數子元素。

參數類型預設值說明
$first 數字

第一個 nth 數字

$last 數字

最後一個 nth 數字


number-between

@include number-between($num, $first, $last) { }

選取介於 $first$last 之間的所有 $num 子元素。

參數類型預設值說明
$num 數字

介於 $first$last 之間的每 n 個數字。

$first 數字

第一個 n 個數字

$last 數字

最後一個 n 個數字