Home  >  Article  >  Web Front-end  >  All common data types of css

All common data types of css

小云云
小云云Original
2017-11-25 09:14:391705browse

In this article, we will talk about the common data types of CSS. There are many formats for attribute values ​​in CSS. In order for the user agent (i.e. browser) to recognize whether a value is valid, it needs to confirm whether the value conforms to one of the formats supported by this type of value. The formats supported by these attribute values ​​are called data types, which are identified in the specification in the form of 3797071296dfca8446f8fa422779c43c.

There are two data types in CSS - specific data types and general data types. A specific data type is associated only with a single attribute or a class of attributes. For example, the data type 51a72c16a181454beb1335050c004065 can only be used as the value of the transform attribute.

In contrast, general data types are not associated with any specific properties. For example, the d82af2074b26fcfe177e947839b5d381 data type has a value of 10px, which can be used for margin, font-size, and a series of other properties.

In this article, I will give an overall introduction to all common data types.

Directory Name Type

Text value Keyword bd9fb4efa67f1df180acc87eb80519ec

Text value Custom keyword e53daba18c25ef518ad73d82fe4f7af3

Text value Quote String 98c455a79ddfebb79781bff588e7b37e

Text value Resource locator 9bb6a7d109b3f2bf35f7e2e9bd87f98a

Basic numerical value Integer 979e7f42ea08258251c39ffe96b911f2

Basic numerical value Real number d80b5def5ed1be6e26d91c2709f14170

Basic value Ratio 5bfe5090b04fb7fd0d6ed7d15c4af1b6

Basic value Percentage 42c97a047d75abc12b9b351eb8562711

Measurement Distance d82af2074b26fcfe177e947839b5d381

Measurement Angle 0c0cb308ee3d2ee3281772bfc9b806c2

Measurement Duration 31f48eb6949585d6c147c2cc44c24eba

Measurement Frequency 1b26ef64c874d94473a4671c85a45a7f

Measurement Resolution f0875990a7c33e8b6db6b54083cd052f

Others Color b10fb37415d019cfffa8c4d7366c607f

Others Pictures dc0870658837139040642baa5555a380

Others Position 7f952ef31037694d232de8bb3c23c71d

Text data type

Keywords

Keyword data type

.foo { border-color: red; position: inherit;
}

These keywords are case-insensitive, and quotation marks cannot be added when used. This avoids confusion with the string data type 98c455a79ddfebb79781bff588e7b37e.

Custom Keywords

The custom keyword data type e53daba18c25ef518ad73d82fe4f7af3 (also written as 028aa264268b1d80e0a56150adf879cc) refers to the keywords defined by the style sheet author. The definition of e53daba18c25ef518ad73d82fe4f7af3 has certain restrictions, such as it cannot be one of the common CSS words.

The most common example of a custom keyword is the value of the animation-name attribute. This property can accept a custom animation as its value. The custom animation name is defined by the author of the style sheet.

@keyframes hulkify {
  from { 
    color: pink; 
    transform: scale(1);
  }
  to { 
    color: green; 
    transform: scale(2);
  }

}.bruce-banner { animation-name: hulkify; }

Quoted string

The string data type 98c455a79ddfebb79781bff588e7b37e refers to any quoted string. This string is enclosed in quotation marks and is an arbitrary sequence of Unicode characters.

.foo::after {  content: "Hello, world!";
}.foo::before {  content: "We can add 'quotes' within quotes \A And move to a separate line";
}

Resource locator

Resource locator 9bb6a7d109b3f2bf35f7e2e9bd87f98a is used to reference resource files or fragments. This data type is usually expressed using the url() function, but in some cases it can also be expressed in the form of 98c455a79ddfebb79781bff588e7b37e, such as in an @import rule.

This data type has three URLs (Uniform Resource Locator).

Absolute URL includes protocol and domain name. The resource specified by this type of URL does not need to be the same as the domain name to which the style sheet belongs.

The file pointed to by the relative URL takes the location of the style sheet file as the base location.

Local URL (fragment URL) is used to point to elements within the main file itself. Referenced by the element's id, not the file path.

/* Absolute URL */@import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro:400"); /* Realtive URL */.foo { background-image: url("../img/bg.png"); }
@import "components/buttons.css"; /* Fragment URL */.bar { filter: url("#blurFilter"); }

Basic numerical types

Integer

Integer type 979e7f42ea08258251c39ffe96b911f2 is an integer defined in mathematics. It is a complete number with no decimal part. Integers include positive and negative integers. The sign of an integer is specified by + or - before the first digit, or defaults to + if nothing is specified.

.foo { z-index: 10; }.foo { z-index: +10; }.bar { z-index: -10; }

real number

The real number typed80b5def5ed1be6e26d91c2709f14170 is a "real number". It can be an integer 979e7f42ea08258251c39ffe96b911f2 , 0 or a decimal fraction. Like integer types, real numbers also have positive and negative values, also indicated by the sign before the first number.

.foo { line-height: 3; }.bar { line-height: -2.5; }.foo { line-height: +5.5; }

ratio

比率数据类型 5bfe5090b04fb7fd0d6ed7d15c4af1b6 表明两个数值之前的关系,这两个数值均为正的整数值 979e7f42ea08258251c39ffe96b911f2 。尽管数学中比率有着多种书写方式,但是在CSS经常被写作 979e7f42ea08258251c39ffe96b911f2 / 979e7f42ea08258251c39ffe96b911f2 。

比率类型的典型用法是用来在媒体查询中指明目标设备的分辨率。

@media screen and (device-aspect-ratio: 16/9) { /* Wide screen displays, iPhone 5 */ }
@media screen and (device-aspect-ratio: 4/3) { … }

百分比

百分比数据类型 42c97a047d75abc12b9b351eb8562711 由一个实数值 d80b5def5ed1be6e26d91c2709f14170 后加一个 % 符号组成。它表示的是其他值的一部分。因此,针对不同的值类型,有不同的百分比数据类型

长度百分比 681b2bd515aa1f62bd1f4d50ed120e94 是长度值 d82af2074b26fcfe177e947839b5d381 的一部分。

数值百分比 37048807626580dd0584665074fc81fa 是数值 d80b5def5ed1be6e26d91c2709f14170 的一部分。

角度百分比 edeb4aedb0fa205d9b967008346802d5 是角度值 0c0cb308ee3d2ee3281772bfc9b806c2 的一部分。

时间百分比 ea74f057a70914f3ec50a34b01b1d330 是长度值 46dd80ba616c57a652514755c74c4211 的一部分。

频率百分比 27dc963f6062b18be37bad7a1f79a1cb 是长度值 1b26ef64c874d94473a4671c85a45a7f 的一部分。

.foo { 
    width: 50%; /*  */
    line-height: 200% /*  */
    voice-pitch: 25% /*  */}

尺寸数据类型

尺寸是数值数据类型中的一种,是一种度量单位。它前半部分由数值组成,后面跟一个单位符号。当数值部分为 0 时,单位可以省略。

距离

距离数据类型 d82af2074b26fcfe177e947839b5d381 表示距离的单位,有两种长度单位。

绝对单位 ,如 px , cm 以及 pt 。这些单位的距离值都是固定的,与物理测量相关。一旦声明,它们的大小不会因为容器元素的字体大小变化而发生改变。

相对单位 ,如 em , rem 以及视口单位。这些单位并没有一个客观的度量标准。相反的,这类单位的实际值由它们的父元素决定。这就意味着它们的大小会因为所依赖元素的大小改变而改变。

 

.foo {
   font-size: 16px; /* absolute */
   width: 50vw; /* relative */}

角度

角度数据类型表示圆的一个角度。存在四种单位来定义角度度量。

deg 单位表示角的度数。一个完整的圆为360度。

grad 表示角的Gradians度。一个完整的圆为400 grad 。

rad 表示角的弧度。一个完整的圆为2π(约为57.29rad)。

turn 表示圆周长。一个完整的圆为1turn.

这些单位都存在正负值之分,表明顺时针或者逆时针。下面的例子中,指出了如何用各种单位表示顺时针90度。

.foo { 
    /* Going clockwise */
    transform: rotate(90deg);    transform: rotate(100grad);    transform: rotate(0.25turn);    transform: rotate(1.57rad);    /* Going anti-clockwise */
    transform: rotate(-270deg);    transform: rotate(-300grad);    transform: rotate(-1.25turn);    transform: rotate(-55.72rad);
}

时长

时长数据类型 46dd80ba616c57a652514755c74c4211 是时间单位。有两种单位能够用来定义时间。

s 表示一秒钟。

ms 表示一毫秒。1秒等于1000毫秒。

.foo { transition-duration: 1s; } 
.bar { transition-duration: 1000ms; }

频率

频率类型 1b26ef64c874d94473a4671c85a45a7f 表示声音的频率。存在两个单位用来定义频率。

kHz 表示千赫兹。

Hz 表示赫兹。1000Hz等于1kHz.

.foo { voice-pitch: 250Hz; } 
.bar { voice-pitch: 1kHz; }

分辨率

分辨率数据类型 f0875990a7c33e8b6db6b54083cd052f 表示用户当前设备的分辨率。分辨率是单一像素点(物理)的大小,通过1CSS英寸、厘米或者像素需要多少像素点能填满来定义。这一计算方式依赖于我们所用的CSS单位,有四种方式可以指定分辨率。

dpi 表示每CSS英寸中物理像素点的个数。

dpcm 表示每CSS厘米中物理像素点的个数。

dppx 表示每CSS像素中物理像素点的个数。

@media (min-resolution: 100ddpx) { .. }
@media (min-resolution: 100dpcm) { .. }
@media (min-resolution: 300dpi) { /* Retina display */ }

其他数据类型

颜色

颜色数据类型 b10fb37415d019cfffa8c4d7366c607f 用来定义颜色值。这一数据类型有两种格式。

关键字形式 :可以使预定义颜色中的一种(如 cornflowerblue ), transparent 以及 currentColor 等关键之。

数值形式 :可以使用颜色表示法中的一种, #rgb , rgb() , rgba() , hsl() , hsla() 。

下例是我们如何用不同的形式实现黑色颜色值。

.foo {   color: black;   color: #000;   color: rgb(0,0,0);   color: rgba(0,0,0,1);   color: hsl(0,0%,0%);   color: hsla(0,0%,0%, 1);
}

图片

图片数据类型 dc0870658837139040642baa5555a380 表示一个2D图像。它可以是以下三种形式中的一种。

URL引用 :通过 9bb6a7d109b3f2bf35f7e2e9bd87f98a 数据类型来指定。

文档中的元素 :通过 element() 函数来指定。(提示:这一函数的支持度较为有限。)

渐变函数 :使用 bd2c3b8af3e0a5639b590da5f6eca814 数据类型来定义。

.foo { background-image: url('path/to/bg.png'); }.bar { background-image: element('#background'); }.baz { background-image: linear-gradient(white, gray); }

位置

位置数据类型 7f952ef31037694d232de8bb3c23c71d 指出了一个元素在容器区域或元素中的位置。它可以使下列三种类型中的一种:

关键字 : top , right , bottom , left 以及 center 。

长度值 。

百分比 ,长度百分比。

下例给出了如何让一个大小为100x100px背景图定位在容器元素(300x300px)的左下角。

.foo { 
  background-position: right bottom;  background-position: 200px 200px;  background-position: 100% 100%;
}

以上就是css的通用数据类型,希望对大家有帮助。

相关推荐:

Summary and detailed explanation of EF general data layer encapsulation class examples

Several commonly used selectors in CSS3

A few useful ones Tips on css functions

The above is the detailed content of All common data types of css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn