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.mzph.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…