14、CSS中颜色设置方法

html-css012

14、CSS中颜色设置方法,第1张

在我们的显示屏中,一个像素点由三原色构成,分别为:红、绿、蓝。然而在计算机中使用0-255来表示某个原色的不同程度,在二进制中,可以使用八位二进制(00000000-11111111)进行表示。在十六进制中用( 00-ff )表示。那么红色(0-255),绿色(0-255),蓝色(0-255)三原色组成的颜色就有256*256*256种,组成了屏幕中五彩缤纷的画面。

由此就可以衍生出颜色的表示方式:

加入透明度:

使用色相表示(hsl):

这是一种将所有颜色对应成一个圆,一个角度代表一种颜色,所以取值范围为0-360,但是它还包括了饱和度和亮度。

h:0-360,色相

s:0-100%,饱和度

l:0-100%,亮度

例如:hsl(0, 50%, 50%)

作用多了去了,例如常见的 :before、:after 伪类,经常被用来辅助生成一些装饰性的东西(折角、抬头、箭头等),能让你少写两层无意义的html标签,配合attr属性,可以动态显示content的值:

<div class="prog" data-pct="20"></div>

.prog:before {content:attr(data-pct) '%'} /* 拼接字符串,js的感觉有木有! */

除此之外,还有 :first-child、:last-child、:nth-child(n)、:focus、:active等,筛选元素简直太方便了。

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title></title>

<style>

body {

background-color: #eaf0f2

}

h1{text-align: center}

.box{width:500pxheight:300pxmargin:0 autoposition:relative}

.img-layer{position: absolutewidth: 500pxheight: 300pxtop: 0left: 0overflow: hidden}

.img-layer img {width: 500pxcursor: pointer}

.img-layer:before{ content: ''

position: absolute

top: 0

right: 0

width: 0

height: 0

border-style: solid

border-width: 0

border-color: rgba(0,0,0,0.2) #fff

border-radius: 0 0 0 4px

box-shadow: 0 1px 1px rgba(0,0,0,0.3), -1px 1px 1px rgba(0,0,0,0.2)

-webkit-transition: all 0.4s ease-out

transition:all 0.4s ease-out}

.img-layer:hover:before{

border-right-width:100px

border-bottom-width:100px

}

</style>

</head>

<body>

<h1>折角效果</h1>

<div class="box">

<div class="img-layer">

<img src="<a href="http://p6.qhimg.com/d/inn/3f563406/table.jpg">http://p6.qhimg.com/d/inn/3f563406/table.jpg</a>" alt="">

</div>

</div>

</body>

</html>

来源于网络