
- CSS 教程
- CSS - 首頁
- CSS - 路線圖
- CSS - 簡介
- CSS - 語法
- CSS - 選擇器
- CSS - 包含
- CSS - 測量單位
- CSS - 顏色
- CSS - 背景
- CSS - 字型
- CSS - 文字
- CSS - 圖片
- CSS - 連結
- CSS - 表格
- CSS - 邊框
- CSS - 塊級邊框
- CSS - 行內邊框
- CSS - 外邊距
- CSS - 列表
- CSS - 內邊距
- CSS - 游標
- CSS - 輪廓
- CSS - 尺寸
- CSS - 捲軸
- CSS - 行內塊
- CSS - 下拉選單
- CSS - 可見性
- CSS - 溢位
- CSS - Clearfix
- CSS - 浮動
- CSS - 箭頭
- CSS - 調整大小
- CSS - 引號
- CSS - 順序
- CSS - 位置
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 聚焦
- CSS - 縮放
- CSS - 平移
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 導航欄
- CSS - 覆蓋層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪裁
- CSS - 書寫模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - 全部
- CSS - 內嵌
- CSS - 隔離
- CSS - 溢位滾動
- CSS - Justify Items
- CSS - Justify Self
- CSS - 製表符大小
- CSS - 指標事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大塊級尺寸
- CSS - 最小塊級尺寸
- CSS - 混合模式
- CSS - 最大內聯尺寸
- CSS - 最小內聯尺寸
- CSS - 偏移量
- CSS - 口音顏色
- CSS - 使用者選擇
- CSS 高階
- CSS - 網格
- CSS - 網格佈局
- CSS - Flexbox
- CSS - 可見性
- CSS - 定位
- CSS - 層
- CSS - 偽類
- CSS - 偽元素
- CSS - @規則
- CSS - 文字效果
- CSS - 分頁媒體
- CSS - 列印
- CSS - 佈局
- CSS - 驗證
- CSS - 圖片精靈
- CSS - !important
- CSS - 資料型別
- CSS3 教程
- CSS3 - 教程
- CSS - 圓角
- CSS - 邊框圖片
- CSS - 多重背景
- CSS - 顏色
- CSS - 漸變
- CSS - 盒陰影
- CSS - 盒裝飾中斷
- CSS - 游標顏色
- CSS - 文字陰影
- CSS - 文字
- CSS - 2D 變換
- CSS - 3D 變換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - 盒尺寸
- CSS - 提示框
- CSS - 按鈕
- CSS - 分頁
- CSS - 變數
- CSS - 媒體查詢
- CSS - 函式
- CSS - 數學函式
- CSS - 遮罩
- CSS - 形狀
- CSS - 樣式圖片
- CSS - 特效性
- CSS - 自定義屬性
- CSS 響應式
- CSS RWD - 簡介
- CSS RWD - 視口
- CSS RWD - 網格檢視
- CSS RWD - 媒體查詢
- CSS RWD - 圖片
- CSS RWD - 影片
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 轉換器
- CSS - 顏色選擇器和動畫
- CSS 資源
- CSS - 有用資源
- CSS - 討論
CSS - 數學函式
CSS 數學函式允許您直接在 CSS 樣式表中執行數學計算。這些函式可用於操作長度、角度、顏色等值。
div{ width: calc(100% - 40px); /* 100% width minus 40px for padding */ width: max(200px, 50%); /* Set width to the maximum value between 200px and 50% of the viewport width */ }
目錄
CSS 中的數學函式型別
CSS 中可以使用幾種型別的數學函式。它們包括
- **基本算術函式** 這包括用於對數值進行計算的 `calc()` 函式。
- **比較函式** 這包括用於比較變數的 `min()`、`max()` 和 `clamp()` 函式。
- **階梯值函式** 這包括用於根據舍入策略計算舍入數字的 `round()` 函式。
- **三角函式** 這些函式(例如 `sin()`、`cos()` 和 `tan()`)將正弦、餘弦和正切等數學函式引入樣式表。
calc 函式
**calc()** 函式是 CSS 中的基本算術函式,允許您對數值進行計算。它可以透過執行加、減、乘、除等數學運算來動態修改屬性值。
示例
這是一個演示 `calc()` 函式用法的示例
<!DOCTYPE html> <html lang="en"> <head> <style> .container { width: 80%; margin: 0 auto; border: 1px solid #000; padding: 20px; } .box { /* 100% width minus 40px for padding */ width: calc(100% - 40px); /* 100% of viewport height minus 20px for padding */ height: calc(100% - 20px); background-color: lightblue; padding: 20px; box-sizing: border-box; } </style> </head> <body> <div class="container"> <div class="box"> This box uses the CSS calc() function to dynamically calculate its width and height. </div> </div> </body> </html>
max 函式
**max()** 函式是 CSS 中的比較函式,允許您從給定值列表中確定最大值。它可以用於比較變數並根據最大值應用條件樣式。
示例
這是一個演示 `max()` 函式用法的示例
<!DOCTYPE html> <html lang="en"> <head> <style> .container { width: 80%; margin: 0 auto; border: 1px solid #000; padding: 20px; } .box { /* Set the width to the maximum value between 200px and 50% of the viewport width */ width: max(200px, 50%); background-color: lightblue; padding: 20px; box-sizing: border-box; } </style> </head> <body> <div class="container"> <div class="box"> This box uses the CSS max() function to set its width to the maximum value between 200px and 50% of the viewport width. </div> </div> </body> </html>
min 函式
**min()** 函式是 CSS 中的比較函式,允許您從給定值列表中確定最小值。它可以用於比較變數並根據最小值應用條件樣式。
示例
這是一個演示 `min()` 函式用法的示例
<!DOCTYPE html> <html lang="en"> <head> <style> .container { width: 80%; margin: 0 auto; border: 1px solid #000; padding: 20px; } .box { /* Set the width to the minimum value between 200px and 50% of the viewport width */ width: min(200px, 50%); background-color: lightblue; padding: 20px; box-sizing: border-box; } </style> </head> <body> <div class="container"> <div class="box"> This box uses the CSS min() function to set its width to the minimum value between 200px and 50% of the viewport width. </div> </div> </body> </html>
比較函式
CSS 比較函式使值的評估更容易,允許根據樣式表中的比較進行條件樣式。
下表列出了比較函式
階梯值函式
階梯值函式透過在 CSS 中啟用屬性值的精確更改和離散跳躍,提供對樣式表的粒度控制。
下表列出了階梯值函式
三角函式
CSS 三角函式透過將正弦、餘弦和正切等數學函式引入樣式表,允許進行更復雜的 desain 更改。
下表列出了三角函式
函式 | 描述 | 示例 |
---|---|---|
sin() | 計算數字的三角正弦。 | |
cos() | 計算數字的三角餘弦 | |
tan() | 計算數字的三角正切。 | |
asin() | 計算數字的三角反正弦。 | |
acos() | 計算數字的三角反餘弦。 | |
atan() | 計算數字的三角反正切。 | |
atan2() | 計算平面中兩個數字的三角反正切。 |
廣告