CSS3新特性详解
本文讲解CSS3相关实用知识点
CSS3相关实用知识点目录
边框设置
颜色设置
背景设置
渐变使用
超出文本设置
阴影设置
CSS3变换设置
过渡设置
动画设置
多列布局
BoxSizing设置
弹性布局
滤镜函数
媒体查询
resize元素
outline偏移
其他的@规则使用
calc
-
边框圆角 border-radius: 10px;
边框图片设置
border: 20px solid transparent;
border-image: url(./2.jpg) 7 31 round;
-
rgb(红,绿,蓝)
background: rgb(0, 0, 112)
background: rgba(0%, 0%, 11%, 0.8)
hsl(色值,饱和度,亮度)
background:hsl(332, 50%, 50%);
background:hsla(332, 50%, 50%, 0.5);
-
背景大小
background-size: 10%;
background-size: 100px;
background-size: cover; 背景覆盖,只要覆盖住元素就可以
background-size: contain; 背景填充,压缩或者拉伸图片以填充满元素
背景裁剪
background-clip: content-box; 按内容裁剪
background-clip: padding-box; 按padding裁剪
background-clip: border-box; 按border裁剪
背景位置
background-origin: content-box; 从内容开始
background-origin: padding-box; 从padding开始
background-origin: border-box; 从border开始
多重背景
background: url("./1.jpg") no-repeat center, url("./2.jpg") no-repeat center, lightblue;
写在前面的背景在最上面,背景颜色只能写在最后面
-
线性渐变
从上到下 background: linear-gradient(red, yellow);
从左到右 background: linear-gradient(to right, red, yellow);
从左下到右上 background: linear-gradient(to top right, red, yellow);
使用角度,0deg表示bottom to top,方向是顺时针旋转
background: linear-gradient(30deg, red, yellow);
多颜色渐变 background: linear-gradient(red, yellow, lime);
指定颜色停止点
background: linear-gradient(red , yellow 30%, lime 90%);
也就是说,在30%的位置必须是yellow,在90%的位置必须是lime,除了可以指定百分比外还可以指定px
background: linear-gradient(red , yellow 30%, lime 120%); 还可以超出范围
渐变重复
background: repeating-linear-gradient(darkmagenta,green 10%, darkmagenta 20%)
背景图渐变色
background: linear-gradient(to right, rgba(228, 108, 10, 0.1), rgb(10, 182, 1)), url("./1.jpg");
径向渐变
基本语法 radial-gradient(shape size at position, color-stop1, color-stop2, ...);
其中 shape 设置渐变结束的形状 circle ellipse
其中 size 设置渐变大小 farthest-corner closest-corner farthest-side closest-side
其中 position 设置渐变的位置 top left ...
从里到外 background: radial-gradient(red, yellow, lime);
从左下到右上 background: radial-gradient(circle farthest-corner at left bottom, red, yellow, lime);
渐变重复
background: repeating-radial-gradient(yellow, white 10%, lime 20%);
-
超出文本显示省略号
p {
width: 400px;
overflow: hidden;
white-space: nowrap;
background: #cdcdcd;
text-overflow: ellipsis;
}
超出文本直接截取
p {
width: 400px;
overflow: hidden;
white-space: nowrap;
background: #cdcdcd;
text-overflow: clip;
}
文本自动换行
p {
width: 400px;
background: #cdcdcd;
word-wrap: break-word;
---也可以设置如下---
word-break: break-all; keep-all
}
-
盒子阴影
基本语法
box-shadow: x偏移量 y偏移量 阴影模糊量 颜色;
box-shadow: 5px 5px 10px #ccc;
box-shadow: 5px 5px 10px red, 10px 10px 20px yellow;
文本阴影
text-shadow: 5px 5px 10px #666;
text-shadow: 5px 5px 10px red, 10px 10px 20px yellow;
-
2D变换
元素位移 transform: translate(200px, 100px);
元素旋转 transform: rotate(30deg); 默认顺时针方向
元素缩放 transform: scale(1.5, 0.8);transform: scale(1.5)
元素扭曲 transform: skew(-40deg, 15deg);
简写 transform: translate(200px, 50px) rotate(180deg) scale(1.5) skew(0, 30deg);
3D变换
body{
perspective: 500px;
}
元素位移 transform: translate3d(20px, 30px, 50px);
元素旋转 transform: rotate3d(0, 1, 0, 60deg); 沿着y轴旋转
元素缩放 transform: scale3d(1, 1, 2) rotate3d(1, 0, 0, 60deg);
-
单个属性动画使用
div{
width: 100px;
height: 100px;
background-color: black;
transition-property: background-color;
transition-duration: 1s;
}
div:hover{
background-color: aqua;
}
多个属性动画使用
div{
width: 100px;
height: 100px;
background-color: black;
transition-property: background-color, width;
transition-duration: 1s, 2s;
}
div:hover{
background-color: aqua;
width: 200px;
}
过渡简写
顺序 transition-property, transition-duration, transition-timing-function, and transition-delay
transition: background-color 1s ease-in 0s;
-
animation具有比transition更强的控制动画的能力
基本使用
div{
width: 100px;
height: 100px;
background-color: black;
position: relative;
animation-name: movebox;
animation-duration: 2s;
}
@keyframes movebox {
from {
left: 0;
}
to {
left: 200px;
}
}
keyframes的定义
@keyframes movebox {
12.5% {left: -50px;}
25% {left: 50px;}
37.5% {left: -25px;}
50% {left: 25px;}
62.5% {left: -10px;}
75% {left: 10px;}
87.5% {left: -5px;}
90% {left: 5px;}
92.5% {left: -3px;}
95% {left: 3px;}
97.5% {left: -1px;}
100% {left: 1px;}
}
动画简写
顺序从上到下
animation-name, 动画名称
animation-duration, 动画持续时间
animation-timing-function, 动画执行函数
animation-delay, 动画延迟时间
animation-iteration-count 动画重复次数
animation-direction 动画在重复播放时是否反序播放,主要和animation-iteration-count配合使用
animation-fill-mode 指定动画结束后,元素在哪个地方,backwards, forwards
animation-play-state 指定动画暂停和结束,paused, running
如 animation: movebox 2s linear 0s 1 alternate backwards running;
-
如果你想布局多列,使用多列布局简直就是神器
基本使用
<div class="box">
<div class="box1">1</div>
<div class="box2">2</div>
</div>
.box {
width: 500px;
column-count: 3;
background-color: gainsboro;
}
.box1 {
background-color: aqua;
}
.box2 {
background-color: bisque;
}
设置列宽
column-width: 200px;
column-width和column-count不能一起使用,因为他们两个作用是一样的,都是来指定显示多少列
设置列与列之间的间隔
默认间隔是1em
column-gap: 0px;
设置列与列之间的间隔线
column-rule: 2px solid red;
-
默认设置width,height是以盒子的内容计算的,可以设置box-siziing改变这一行为
box-sizing: border-box;
-
.box {
width: 500px;
height: 500px;
background-color: red;
filter: blur(5px); 设置模糊程度
filter: contrast(50%); 设置亮度
filter: drop-shadow(4px 4px 10px orange); 设置阴影,和box-shadow类似
filter: grayscale(50%); 设置灰度
filter: hue-rotate(480deg); 设置颜色旋转角度
filter: invert(100%); 设置颜色反转
filter: opacity(20%); 设置背景透明
filter: sepia(62%); 设置复古
filter: saturate(20%); 设置饱和度
}
和写顺序 filter: blur() | brightness() | contrast() | drop-shadow() | grayscale() | hue-rotate() | invert() | opacity() | sepia() | saturate()
-
媒体查询是做响应式布局必备知识
@media screen and (max-width: 767px) { } 手机
@media screen and (min-width: 768px) and (max-width: 1023px) { } ipad
@media screen and (min-width: 1024px) { } 小电脑
@media screen and (min-width: 1280px) { } 中电脑
...
-
.box {
width: 300px;
min-height: 100px;
overflow: auto;
border: 1px solid black;
resize: horizontal; 水平可拖动
resize: both; 随意拖动
resize: none; 清楚拖动
}
-
.box {
width: 300px;
height: 300px;
border: 1px solid #ccc;
outline: 2px solid red;
outline-offset: 10px; 外移
outline-offset: -10px; 内移
}
-
设置css编码
@charset "UTF-8"; 设置在外部样式表文件的头部
设置自定义字体
@font-face {
font-family: "OpenSansBold";
src: url("../fonts/OpenSans-Bold.eot");
src: url("../fonts/OpenSans-Bold.ttf") format("truetype");
}
然后可以这样使用
div{
font-family: "OpenSansBold";
}
导入css文件
@import url("css/layout.css");
@import url("css/print-style.css") print; 指定设备
-
calc用来计算元素的大小和位置
.center{
position: absolute;
background: red;
height: 200px;
width: 200px;
top: calc(50% - 200px / 2);
left: calc(50% - 200px / 2);
} <div class="center"></div>
CSS3新特性详解的更多相关文章
- ES6,ES2105核心功能一览,js新特性详解
ES6,ES2105核心功能一览,js新特性详解 过去几年 JavaScript 发生了很大的变化.ES6(ECMAScript 6.ES2105)是 JavaScript 语言的新标准,2015 年 ...
- 《Android群英传》读书笔记 (5) 第十一章 搭建云端服务器 + 第十二章 Android 5.X新特性详解 + 第十三章 Android实例提高
第十一章 搭建云端服务器 该章主要介绍了移动后端服务的概念以及Bmob的使用,比较简单,所以略过不总结. 第十三章 Android实例提高 该章主要介绍了拼图游戏和2048的小项目实例,主要是代码,所 ...
- Android群英传笔记——第十二章:Android5.X 新特性详解,Material Design UI的新体验
Android群英传笔记--第十二章:Android5.X 新特性详解,Material Design UI的新体验 第十一章为什么不写,因为我很早之前就已经写过了,有需要的可以去看 Android高 ...
- Java9 新特性 详解
作者:木九天 < Java9 新特性 详解 > Java9 新特性 详解 摘要: 1.目录结构 2.repl工具 jShell命令 3.模块化 4.多版本兼容jar包 5.接口方 ...
- 点击--》java9 新特性 详解
引言: 点击-->java9 新特性 详解 点击-->java8 新特性 详解 正题: 1.局部变量var 将前端思想var关键字引入java后段,自动检测所属于类型,一种情况除外,不能为 ...
- java10 新特性 详解
引言: 点击-->java9 新特性 详解 点击-->java8 新特性 详解 正题: 1.局部变量var 将前端思想var关键字引入java后段,自动检测所属于类型,一种情况除外,不能为 ...
- Java基础学习总结(33)——Java8 十大新特性详解
Java8 十大新特性详解 本教程将Java8的新特新逐一列出,并将使用简单的代码示例来指导你如何使用默认接口方法,lambda表达式,方法引用以及多重Annotation,之后你将会学到最新的API ...
- Java8 Stream新特性详解及实战
Java8 Stream新特性详解及实战 背景介绍 在阅读Spring Boot源代码时,发现Java 8的新特性已经被广泛使用,如果再不学习Java8的新特性并灵活应用,你可能真的要out了.为此, ...
- CSS3新增特性详解(一)
注:由于CSS3的新特性较多,所以分两篇博文来说明.第一篇主要包括新的选择器.文字及块阴影.多背景图.颜色渐变.圆角等.第二篇主要细说CSS3的各种动画效果,如:旋转.移动.缩放等,还包括图标字体的应 ...
随机推荐
- CentOS 7 安装 maven
下载地址 http://maven.apache.org/download.cgi 版本 apache-maven-3.3.9 -bin.tar.gz tar -xvf apache-maven-3. ...
- processing学习整理---Input(输入)
1.鼠标1D. 左右移动鼠标可移动天平. “mouseX”变量用于控制矩形的大小和颜色. void setup(){ size(640,360); noStroke(); colorMode(RGB, ...
- CentOS 7(64位) 下Docker的安装
系统要求是64位,内核版本至少3.10. 首先添加yum软件源: 之后更新yum软件源缓存,并安装docker-engine 查看docker 版本: Cannot connect to the Do ...
- 泛型学习第一天:List与IList的区别 (二)
原文: 探讨Ilist<>与List<> 首先要了解一点的是关于接口的基础知识: 接口不能直接实例化但是接口派生出来的抽象类可以实例化所有派生出来的抽象类都可以强制转换成接口的 ...
- JAVA8新特性——方法引用
JAVA9都要出来了,JAVA8新特性都没搞清楚,是不是有点掉队哦~ 在Lamda新特性的支持下,JAVA8中可以使用lamda表达式来创建匿名方法.然而,有时候我们仅仅是需要调用一个已存在的方法(如 ...
- java collection接口源码
package java.util; 02. 03./* 04.* 1.Collection接口是集合继承关系中的根接口(root interface),有些集合允许重复元素, 05.* 有些集合有序 ...
- 项目开发之git配置
1.本地安装git配置 安装步骤,这里不详细介绍,软件下载然后安装即可. 查看git安装版本 #git --version 2.git密钥生成 ssh-keygen -t rsa -C "f ...
- shitf+tab
在eclipse中,shitf+tab可以使代码向左移动.
- [Kafka] - Kafka内核理解:分布式机制
一个Topic中的所有数据分布式的存储在kafka集群的所有机器(broker)上,以分区(partition)的的形式进行数据存储:每个分区允许存在备份数据/备份分区(存储在同一kafka集群的其它 ...
- Linux 系统实时监控 —— Glances
早些时候,我们提到过有很多可以用来监视系统性能的 Linux 系统监视工具. 但我们估计,或许更多的用户会倾向与绝大多数 Linux 发行版都带的工具 (top 命令). top 命令是 Linux ...