css中變量_CSS中的變量

css中變量

CSS | 變數 (CSS | Variables)

CSS variables allow you to create reusable values that can be used throughout a CSS document.

CSS變量允許您創建可在CSS文檔中使用的可重用值。

In CSS variable, function var() allows CSS variables to be accessed.

CSS變量中 ,函數var()允許訪問CSS變量。

For example, in CSS it's quite common to reuse a single color or text-size throughout the code, this would mean reusing the same color or text-size value several times throughout a document. With CSS variables the color or text-size value can be assigned to a variable and used in multiple places. This makes changing values easier and is more convenient than using traditional CSS values.

例如 ,在CSS中,在整個代碼中重復使用單一顏色或文本大小是很普遍的,這意味著在整個文檔中多次重復使用相同的顏色或文本大小。 使用CSS變量,可以將顏色或文本大小值分配給變量,并在多個位置使用。 與使用傳統CSS值相比,這使更改值更容易并且更方便。

Note: Variables should be declared in a CSS selector that defines variables scope. In the global scope, you can use either the: root or the body selector.

注意:變量應在定義變量范圍CSS選擇器中聲明。 在全局范圍內,可以使用: root或body選擇器

The name of the variable must start with two dashes (--), also the name of the variable is case sensitive.

變量的名稱必須以兩個破折號( - )開頭,并且變量的名稱區分大小寫。

CSS變量| 有效/無效 (CSS variables | Valids/Invalids)

When naming CSS variables, it contains only letters and dashes just like other CSS properties but it should start with double dashes (--).

命名CSS變量時,與其他CSS屬性一樣,它僅包含字母和破折號,但應以雙破折號( - )開頭。

    //These are Invalids variable names 
--123color: blue; 
--#color: red;
--$width: 100px; 
//Valid variable names
--color: red;
--bg-color: yellow ;
--width: 100px; 

可變屬性 (Variable properties)

  1. Variable color

    顏色可變

  2. Variable dimension

    可變尺寸

  3. Variable cascading

    可變級聯

Let's look at each property more closely...

讓我們更仔細地觀察每個屬性...

a)可變顏色 (a) Variable color)

This property allows us to reuse a single color throughout the code. CSS Variables the color value can be assigned to a variable and used in multiple places.

此屬性使我們可以在整個代碼中重用單一顏色。 CSS變量的顏色值可以分配給一個變量,并可以在多個地方使用。

Syntax:

句法:

Element {
--main-bg-color: coral;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
:root {
--primary-color: blue;
}
#div1 {
background-color: var(--primary-color);
padding: 5px;
}
#div2 {
background-color: var(--primary-color);
padding: 10px;
}
#div3 {
background-color: var(--primary-color);
padding: 15px;
}
</style>
</head>
<body>
<div id="div1"> Variables in CSS.</div>
<br>
<div id="div2">Variables in CSS.</div>
<br>
<div id="div3">Variables in CSS.</div>
</body>
</html>

Output

輸出量

Variables in CSS | Example 1

In the above example, we have reused blue color in three division element.

在上面的示例中,我們在三個劃分元素中重用了藍色。

b)尺寸可變 (b) Variable dimensions)

This property allows us to reuse a few sets of dimensions throughout the code.

此屬性使我們可以在整個代碼中重用幾組維度。

Syntax:

句法:

Element {
--W200: 200px;
--W10: 10px;
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
:root {
--W200: 200px;
--W10: 10px;
}
#div1 {
width: var(--W200);
margin: var(--W10);
padding: 5px;
}
#div2 {
width: var(--W200);
margin: var(--W10);
padding: 10px;
}
</style>
</head>
<body>
<div id="div1">Variables in CSS.</div>
<br>
<div id="div2">Variables in CSS.</div>
<br>
</body>
</html>

Output

輸出量

Variables in CSS | Example 2

In the above example, the same dimensions are used in both the divisions.

在上面的示例中,兩個分區使用相同的尺寸。

c)可變級聯 (c) Variable cascading)

Variables in CSS cascade in the same way as other properties, and can be reused safely.

CSS中的變量以與其他屬性相同的方式級聯,并且可以安全地重用。

You can define variables multiple times and only the definition with the highest specificity will apply to the element selected.

您可以多次定義變量,并且只有具有最高特異性的定義才適用于所選元素。

Syntax:

句法:

Element {
--color: green;
border: 1px solid var(--color);
}

Example:

例:

<!DOCTYPE html>
<html>
<head>
<style>
.button {
--color: green;
border: 1px solid var(--color);
color: var(--color);
}
.button:hover {
--color: blue;
}
.button_red {
--color: red;
}
</style>
</head>
<body>
<a class="button">Button Green</a>
<a class="button button_red">Button Red</a>
<a class="button">Button Hovered On</a>
</body>
</html>

Output

輸出量

Variables in CSS | Example 3

In the above example, if we hover over the last button the color changes to blue.

在上面的示例中,如果將鼠標懸停在最后一個按鈕上,顏色將變為藍色。

翻譯自: https://www.includehelp.com/code-snippets/variables-in-css.aspx

css中變量

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377146.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377146.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377146.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

位圖像素的顏色 攜程編程大賽hdu

位圖像素的顏色 Time Limit: 2000/1000 MS (Java/Others) MemoryLimit: 32768/32768 K (Java/Others) Total Submission(s): 0 Accepted Submission(s): 0 Problem Description 有一個在位圖上畫出矩形程序&#xff0c;一開始位圖都被初始化為白色&#xff08;RGB顏色表示…

《MySQL——InnoDB與Memory以及臨時表》

InooDB與Memory 數據組織方式不同&#xff1a; InnoDB引擎把數據放在主鍵索引上&#xff0c;其他索引上保存的是主鍵id。為索引組織表Memory引擎把數據單獨存放&#xff0c;索引上保存數據位置。為堆組織表 典型不同處&#xff1a; 1、InnoDB表的數據總是有序存放的&#x…

Oracle 用戶 profile 屬性 轉

--查看profile 內容 select * from dba_profiles where profilePF_EAGLE; --查看用戶的profiles select username,profile from dba_users; --查看是否啟用動態資源限制參數 SHOW PARAMETER RESOURCE_LIMIT; --啟用限制 ALTER SYSTEM SET RESOURCE_LIMITTRUE SCOPEBOTH; --創建…

CUL8R的完整形式是什么?

CUL8R&#xff1a;稍后再見 (CUL8R: See You Later) CUL8R is an abbreviation of "See You Later". CUL8R是“稍后見”的縮寫 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook, Yahoo M…

SuperSpider——打造功能強大的爬蟲利器

SuperSpider——打造功能強大的爬蟲利器 博文作者&#xff1a;加菲 發布日期&#xff1a;2013-12-11 閱讀次數&#xff1a;4506 博文內容&#xff1a; 1.爬蟲的介紹 圖1-1 爬蟲&#xff08;spider) 網絡爬蟲(web spider)是一個自動的通過網絡抓取互聯網上的網頁的程序&#xf…

《MySQL——關于grant賦權以及flush privileges》

先上總結圖&#xff1a; 對于賦予權限或者收回權限還是創建用戶&#xff0c;都會涉及兩個操作&#xff1a; 1、磁盤&#xff0c;mysql.user表&#xff0c;用戶行所有表示權限的字段的值的修改 2、內存&#xff0c;acl_users找到用戶對應的對象&#xff0c;將access值修改 g…

對Spring的理解

1、Spring實現了工廠模式的工廠類&#xff0c;這個類名為BeanFactory實際上是一個接口&#xff0c;在程序中通常BeanFactory的子類ApplicationContext。Spring相當于一個大的工廠類&#xff0c;在其配置文件中通過<bean>元素配置用于創建實例對象的類名和實例對象的屬性。…

Java中的null是什么?

As we know null is an important concept in every language not only in Java but here we will study various factors regarding null. 我們知道null在每種語言中都是重要的概念&#xff0c;不僅在Java中&#xff0c;在這里我們還將研究有關null的各種因素。 null is a ver…

《MySQL——分區表小記》

分區表的組織形式 以年份為分割方式&#xff0c;對表進行分割&#xff1a; CREATE TABLE t (ftime datetime NOT NULL,c int(11) DEFAULT NULL,KEY (ftime) ) ENGINEInnoDB DEFAULT CHARSETlatin1 PARTITION BY RANGE (YEAR(ftime)) (PARTITION p_2017 VALUES LESS THAN (201…

實戰Windows下安裝boost

Boost大部分組件無需編譯可直接包含頭文件使用&#xff0c;但還有一些庫需要編譯成靜態庫或動態庫才能使用。可使用下文將提到的bjam工具&#xff1a;bjam --show-libraries 查看必須編譯才能使用的庫。 編譯安裝環境&#xff1a;Win7&#xff0c;VS2008(msvc-9.0) 1. 下載boos…

postgresq dur_DUR的完整形式是什么?

postgresq dur杜爾(DUR)&#xff1a;您還記得嗎&#xff1f; (DUR?: Do You Remember?) DUR? is an abbreviation of "Do You Remember?". DUR&#xff1f; 是“您還記得嗎&#xff1f;”的縮寫。 。 It is an expression, which is commonly used in messaging…

gsettings-desktop-schemas : 破壞: mutter (< 3.31.4) 但是 3.28.4-0ubuntu18.04.2 正要被安裝解決方案

完整報錯&#xff1a; dyydyy-Lenovo-ThinkBook-14-IIL:~$ sudo apt install build-essential 正在讀取軟件包列表... 完成 正在分析軟件包的依賴關系樹 正在讀取狀態信息... 完成 有一些軟件包無法被安裝。如果您用的是 unstable 發行版&#xff0c;這也許是 因…

程序內存檢測

本文參考自&#xff1a;http://www.cnblogs.com/hebeiDGL/p/3410188.html static System.Windows.Threading.DispatcherTimer dispacherTimer;static string total "DeviceTotalMemory";static string current "ApplicationCurrentMemoryUsage";static s…

動態規劃天天練1

本來很久以前就打算每天練一道動態規劃題的&#xff0c;但每每由于作業太多而中斷&#xff0c;現在終于停課了......廢話不多說&#xff0c;第一道題就給了我迎頭一棒&#xff0c;不僅想了很久&#xff0c;連題解都看了很久。。。水平相當不足啊啊&#xff0c;不多說廢話&#…

AAS的完整形式是什么?

AAS&#xff1a;活著和微笑 (AAS: Alive And Smiling) AAS is an abbreviation of "Alive And Smiling". AAS是“活著和微笑”的縮寫 。 It is an expression, which is commonly used in messaging or chatting on social media networking sites like Facebook, Y…

《MySQL 8.0.22執行器源碼分析(1)——execute iterator一些記錄》

目錄一條語句的函數調用棧順序8.0使用迭代器模式改進executorint *handler*::ha_rnd_next(*uchar* **buf*)int *TableScanIterator*::Read()int FilterIterator :: Read&#xff08;&#xff09;int HashJoinIterator::Read()int NestedLoopIterator :: Read&#xff08;&#…

關于autoupgader的狗屎問題

由于win7和xp的權限問題&#xff0c;導致這個自動升級玩意不正常。這個狗屎問題很簡單&#xff0c;把exe文件的兼容性設定該一下。真是氣死灑家了。轉載于:https://www.cnblogs.com/usegear/p/3679097.html

strcspn函數

函數原型&#xff1a;extern int strcspn(char *str1,char *str2) 參數說明&#xff1a;str1為參照字符串&#xff0c;即str2中每個字符分別與str1中的每個字符比較。 所在庫名&#xff1a;#include <string.h> 函數功能&#xff1a;以str1為參照&#xff0c…

c語言 sqlite_SQLite與C語言

c語言 sqliteSQLite數據庫簡介 (Introduction to SQLite database) SQLite is a relational database; it is used for embedded devices. Now a day it is using worldwide for different embedded devices. SQLite是一個關系數據庫。 它用于嵌入式設備。 如今&#xff0c;它已…

《MySQL 8.0.22執行器源碼分析(2)解讀函數 ExecuteIteratorQuery》

函數代碼 bool SELECT_LEX_UNIT::ExecuteIteratorQuery(THD *thd) {THD_STAGE_INFO(thd, stage_executing);DEBUG_SYNC(thd, "before_join_exec");Opt_trace_context *const trace &thd->opt_trace;Opt_trace_object trace_wrapper(trace);Opt_trace_object…