CSS3

2019-03-26  本文已影响0人  致自己_cb38

一、CSS3

二、选择器

1.基本选择

1)通配符选择器(*)
2)id选择器(#)
3)class选择器(.)
4)标签选择器(element)

2.群组选择器(并列)
selector,selector{

}
3.层次选择器

1)后代选择器(里面)

selector selector{

}

2)子代选择器

selector>selector{

}

3)相邻兄弟选择器(只能向后)

selector+selector{

}

4)普通兄弟选择器(只能向后)

selector~selector{
}
4.伪类选择器

1)hover
鼠标悬浮
能够使用css实现的hover操作不用js
2)focus
鼠标焦点
3)link
默认的超链样式
4)active
点击的一瞬间
5)visted
访问过之后

5.目标伪类选择器

target 选择器 --- 结合锚点

6.UI元素状态伪类选择器语法

1):checked
2):enabled
3):disabled

7.结构伪类

1)E:root
查找当前元素所在的根节点。HTML
2):first-child 与 :last-child

8.否定 not
9.属性选择器

1)[attr=value]
属性等于value
2)[attr^=value]
属性值以value开头
3)[attr$=value]
属性值以value结束
4)[attr~=value]
包含
5)[attr*=value]
模糊匹配
6)[attr|=value]
用于选取带有以指定值开头的属性值的元素,该值必须是整个单词
7)[attr]
包含有这个属性的标签元素

10.伪元素选择器

1)::after
在元素的最后添加一个新的标签
2)::before
在元素的最前面添加一个标签
3):selection
用于选中的部分
4)::first-letter
第一个字母
5)::first-line
第一行文字

三、优先级

1、级优先级 !important 不允许覆盖。

行级优先级 -----不允许使用

2、级优先级 id选择器>class选择器

3、级优先级 属性>标签

四、盒子模型

布局就是使用盒子模型。

1) 标准盒子模型

视觉宽度 = width + padding2 + border2

image.png
2) 怪异盒子模型

视觉宽度 = 宽度 = width


image.png

五、2D变换

1、transform:2D变换

-webkit- chrome , safari

-moz- FF firefox

-ms- IE

-o- opera 欧朋

transform : translate(20px,20px);

-webkit-transform : translate(20px,20px);

-o-transform : translate(20px,20px);

-ms-transform : translate(20px,20px);

-moz-transform : translate(20px,20px);  
1) transform-orgin

改变旋转中心位置

2) translate translateX translateY translateZ

相当于相对定位。

transform:translate(x,y);

image.png
3) rotate rotateX rotateY rotateZ

旋转

transform:rotate(30deg);

image.png
2、 scale() scaleX scaleY scaleZ

缩放;一个参数表示x,y相同的倍数

transform:scale(X倍数,Y倍数);

image.png
3、 skew() skewX skewY

扭曲,倾斜。

包含两个参数值,分别表示X轴和Y轴倾斜的角度,如果第二个参数为空,则默认为0,参数为负表示向相反方向倾斜。

transform:skew(xdeg , ydeg);

image.png
4、 matrix()

matrix()方法和2D变换方法合并成一个。
matrix 方法有六个参数,包含旋转,缩放,移动(平移)和倾斜功能。

六、过渡

CSS3中,我们为了添加某种效果可以从一种样式转变到另一个的时候,无需使用Flash动画或JavaScript。

transition:四个参数如下。

transition-property: 变换的属性

transition-duration: 花费的时间

transition-timing-function: 动画效果

transition-delay: 延时
image.png

七、动画

结合CSS函数。

@keyframes

@keyframes animate_name{
    from{

    }
    to{

    }
}

@keyframes animate_name{
     10%{

      }
       20%{

      }
      100%{

      }
}

格式

animation: name duration timing-function delay iteration-count direction fill-mode play-state;
image.png

正面屏幕:x轴正后负前,y轴正右负坐,translatez垂直屏幕,rotatey画圈

背向屏幕的时候是否可见 hidden | visible

animation-fill-mode: none|forwards|backwards|both|initial|inherit;

transform--style属性指定嵌套元素是怎样在三维空间中呈现。

注意: 使用此属性必须先使用 transform属性.


image.png

八、边框

1、border :1px solid #ccc;
border-top|border-left | border-bottom | border-right

border-width

border-style

border-color
2、圆角 border-box
border-radius: 百分比,像素单位。 多个值。

border-radius:50%; 圆的实现

border-top-left-radius: 左上角

border-bottom-right-radius: 右下角
3、border-image
border-image: source slice/width/outset repeat|initial|inherit;
image.png image.png image.png

九、box-shadow:盒子阴影

image.png

box-shadow:-10px -10px 20px 10px green;


image.png
  1. 使用box-shadow设置一个阴影,阴影也会具有背景图片。

  2. 使用定位,下面的稍大具有透明度。

  3. 边框实现背景图,需要对背景图进行移动位置。

  4. 让背景图片从边框开始铺 background-origin,设置边框颜色的透明度为半透明 rgba()。

十、CSS计算函数 calc()

div{

     width:200px;

     height:200px;

     background: red;

     /*margin:-100px auto;*/

     position: relative;

     top:calc(50% - 100px);

}

注意:calc() 函数里面的运算符号两边必须加上空格。

十一、垂直居中的实现方式

  1. 定位+计算

  2. 定位+margin

  3. 垂直居中的四边定位方式:

image.png

十二、背景图片

1、背景图片地址

background-image:url()

可以加载多个背景图片,每一个背景图片都是需要一个url。中间使用逗号隔开。对应的其他背景属性比如大小,重复也都是需要逗号隔开表示多个。

2、背景图片的位置

background-Origin:定位从哪里开始铺

background-position: 定位图片的位置

image.png
3、背景图片的剪切位置

background-clip: border-box | content-box | padding-box.

可以结合background-origin一起使用。用于切割背景图片显示的位置。

4、background-attachment

设置背景图像是否固定或者随着页面的其余部分滚动

body { 
  background-image: url(bgimage.gif); 
  background-attachment: fixed;
}
image.png

十三、渐变色

线性渐变: linear-gradient

径向渐变:radial-gradient

1、线性渐变

linear-gradient(方向,颜色,颜色。。。);

#grad {

  background: -webkit-linear-gradient(left, red , blue); /* Safari 5.1 - 6.0 */

  background: -o-linear-gradient(right, red, blue); /* Opera 11.1 - 12.0 */

  background: -moz-linear-gradient(right, red, blue); /* Firefox 3.6 - 15 */

  background: linear-gradient(to right, red , blue); /* 标准的语法 */

}

说明: 标准属性方向里面需要有to关键字,表示终点。
起点和终点可以是上下左右,也可以是顶点。也可以是一个角度(180deg)。

image.png
重复线性渐变
background: repeating-linear-gradient(red, yellow 10%, green 20%);

说明:20%表示线性渐变占用的宽度,其他的宽度使用平铺的方式覆盖。

2、径向渐变
1) 形状:

shape 参数定义了形状。它可以是值 circle 或 ellipse。其中,circle 表示圆形,ellipse 表示椭圆形。默认值是 ellipse。

2) 尺寸:

closest-side

farthest-side

closest-corner

farthest-corner

3) 重复的径向渐变

repeating-radial-gradient()

十四、文本

1、text-shadow:文本阴影

文字阴影效果,具有偏移量

text-shadow: h-shadow v-shadow blur color;
image.png
2、text-overflow:文字溢出
image.png
案例:

1)单行文本超出显示省略号。

overflow: hidden;  // 超出隐藏
white-space: nowrap; // 强制不换行
text-overflow: ellipsis; // 文本超出显示省略号

2)多行文本超出显示省略号。

text-overflow:ellipsis;

display:-webkit-box;  /** 设置显示属性为伸缩盒子 **/

-webkit-box-orient: vertical; /** 设置或检索伸缩盒对象的子元素的排列方式 **/

-webkit-line-clamp: 3;  /** 能够显示的行数 **/

overflow: hidden;
3、word-wrap:单词折叠

word-wrap:normal | break-word;

4、文本最后一行对其方式
text-align-last: auto|left|right|center|justify|start|end|initial|inherit;
image.png

十五、CSS字体

字体:特殊的图片。但是不是图片。

//定义一个字体

@font-face{

  font-family: 名字;

  src:路径;

}

//使用

div{

  font-family: 定义好的名字;

}

应用:字体图标

阿里巴巴矢量图库:

@font-face {

    font-family: 'iconfont';

    src: url('iconfont.eot');

    src: url('iconfont.eot?#iefix') format('embedded-opentype'),

    url('iconfont.woff2') format('woff2'),

    url('iconfont.woff') format('woff'),

    url('iconfont.ttf') format('truetype'),

    url('iconfont.svg#iconfont') format('svg');

}

.iconfont {

    font-family: "iconfont" !important;

    font-size: 16px;

    font-style: normal;

    -webkit-font-smoothing: antialiased;

    -moz-osx-font-smoothing: grayscale;

}
image.png

十六、用户界面

1、box-sizing

定义盒子模型。

标准盒子:content-box

怪异盒子:border-box

2、resize 调整大小
resize: none|both|horizontal|vertical:
3、outline 轮廓线

轮廓线类似于边框,但是与边框不同。默认的轮廓线不占据空间,而边框占据空间。

outline: 1px solid #ccc;
outline-offset: 2px ;

十七、图片

1、图片圆角
之前:

<div><img src=””></div>

div{

    width:200px;

    height:200px

    border-radius:50%;

    overflow:hidden;

}

div>img{

    width:100%;

    height:100%;

}

现在:

img{

    width:200px;

    height:200px;

    border-radius:50%;

}

十八、响应式图片

响应式:根据屏幕宽度去改变显示状态。

图片要做到响应式,只需要设置宽度(百分比),高度自动(auto)。

十九、滤镜

CSS filter 属性用为元素添加可视效果 (例如:模糊与饱和度) 。

滤镜参考手册:http://www.runoob.com/cssref/css3-pr-filter.html

上一篇 下一篇

猜你喜欢

热点阅读