1 CSS3 选择器

1.1 基本选择器

1.2 层级

  • 空格

  • >

  • + .item+li

  • ~ .item~p

1.3 属性选择器

  • [attr]

  • [attr=value]

  • [attr^=value]

  • [attr$=value]

  • [attr*=value]

  • [][][]

1.4 伪类选择器

  • :link

  • :visited

  • :hover

  • :active

  • :focus

  • :first-child .list li:first-child

  • :last-child

  • :nth-child() 从1开始 odd even

  • :nth-last-child() 从1开始

  • :only-child li:only-child

  • :first-of-type

  • :last-of-type

  • nth-of-type()

  • nth-last-of-type()

  • only-of-type

<ul>
<li></li>
<li></li>
<p></p>
<li>li:nth-of-type(3) </li>
<li></li>
<li></li>
</ul>

li:nth-of-type(3)   #选择到
li:nth-child(3)   #没有满足条件的元素

1.5 伪元素选择器

  • ::before .item::before

  • ::after .clearfix::after {content:''; display:block; clear:both}

<div class="nav clearfix"> 
子元素浮动
[::after 此处是伪元素创建的]
</div>


<div class="banner">
</div>
  • ::first-letter

  • ::first-line

  • ::selection

  • ::placeholder ::placeholder {color:red} <input placeholder="请输入用户名">

2 CSS3 基础

2.1 新增颜色单位

  • rgba() 不透明0~1

2.2 新增长度单位

  • rem

  • vw

  • vh

3 新增的CSS3属性

3.1 边框圆角

border-radius 长度单位
border-top-left-radius
border-top-righ-radius
border-bottom-left-radius
border-bottom-right-radius

3.2 布局

display: 值很多很多 .... table table-row...
box-sizing: content-box(默认值) / border-box

3.3 外轮廓

outline:1px solid #ccc
outline-style
outline-color
outline-width

3.4 不透明度

opacity: 0~1

3.5 阴影

box-shadow:水平偏移 垂直偏移;   偏移可以负值
box-shadow:水平偏移 垂直偏移 颜色;
box-shadow:水平偏移 垂直偏移 模糊值 颜色; /*最常见的*/
box-shadow:水平偏移 垂直偏移 模糊值 外延值 颜色;
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>盒子阴影</title>
<style>
.item {
display: inline-block;
margin:20px;
width: 100px;
height: 100px;
border: 1px solid #999;
} .item01 {
box-shadow: 10px 10px;
}
.item02 {
box-shadow: 3px 3px #ccc;
}
.item03 {
/*大部分 需要设置这几个值*/
box-shadow: 10px 10px 10px #ccc;
}
.item04 {
/*外延值*/
box-shadow: 0px 0px 0px 120px #ccc;
} .item05 {
/*多重阴影*/
box-shadow: 0px 0px 3px 5px red,
0px 0px 3px 10px orange,
0px 0px 3px 15px yellow,
0px 0px 3px 20px green,
0px 0px 3px 25px cyan,
0px 0px 3px 30px blue,
0px 0px 3px 35px purple;
}
</style>
</head>
<body>
<h1>阴影</h1>
<hr> <div class="item item01">01</div>
<div class="item item02">02</div>
<div class="item item03">03</div>
<div class="item item04">04</div>
<div class="item item05">05</div>
<div class="item item06">06</div> <hr> </body>
</html>

阴影

 

3.5 背景

background-size: cover / contain / 400px 300px / 100% 100%
background: color image postion/size repeat attachment
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>背景</title>
<style>
.item {
/*display: block;*/
width: 300px;
height: 300px;
border: 1px solid #ccc;
background: url("./images/meinv02.jpg") no-repeat; /*设置背景图片的尺寸*/
/*background-size: cover; 优先 铺满元素。 多余的图片裁掉 保证原图比例*/
/*background-size: contain; 优先 保证图片显示完整,可能元素不能铺满。 保证原图比例*/ /*background-size:100px 200px;指定背景大小*/
/*background-size:100% 100%;*/ /*background: url('./images/meinv02.jpg') 10px 20px/cover;*/
}
</style>
</head>
<body>
<div class="item"> </div>
</body>
</html>

背景

3.6 CSS3变换

  • transform

    translatex() 
    translatey()
    translate(x, y)
    rotate() 角度 deg
    skewx() 角度deg
    skewy()
    skew(x, y)
  • transform-origin 变换的原点。 对translate没有意义。 对rotate影响大

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>变换</title>
<style>
.box {
display: inline-block;
margin: 30px;
width: 100px;
height: 100px;
border:2px dashed orange; vertical-align: middle;
}
.item {
border: 1px solid #999;
background: #ccc;
height:99px;
} .item01 {
/*位移 移动*/
transform: translate(20px, 20px);
/*transform: translatex(10px) translatey(10px);*/
/*transform: translatey(10px);*/
} .item02 {
/*旋转 deg角度 0~360deg*/
transform: rotate(60deg)
} .item03 {
/*扭曲*/
transform: skewx(60deg) skewy(60deg);
} .content {
margin: 30px;
width: 100px;
height: 100px;
border: 1px solid #999;
transform: rotate(60deg);
transform-origin: left top;/*transform-origin 变换的原点*/
}
</style>
</head>
<body> <div class="box">
<div class="item item01"></div>
</div> <div class="box">
<div class="item item02">HELLO</div>
</div> <div class="box">
<div class="item item03">HELLO</div>
</div> <hr> <div class="content">
HELLO
</div> </body>
</html>

变换

3.7 过渡效果

哪些CSS属性可以过渡

长度 (padding margin width height  left/top/right/bottom border-width  background-position ...)
颜色
变换
纯数字 (opacity、z-index)
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS3过渡</title>
<style>
.box {
width: 100px;
height: 100px;
background: red;
/*display: block;*/
/*visibility: visible;*/ border:10px solid purple; /*过渡*/
/* transition:3s; */
transition-property: width,height;
transition-duration: 5s;
transition-timing-function: ease;
transition-delay:3s; transition: all ease 3s 1s;
transition: 4s;
transition: all 4s; }
.box:hover {
/*display: none;*/
/*visibility: hidden;*/
width: 200px;
height: 200px;
background: green; border:20px dashed purple; }
</style>
</head>
<body>
<h1>transition</h1>
<hr>
<div class="box"> </div> <hr> <p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Aperiam dolore veritatis, ducimus maxime fugiat unde inventore aspernatur mollitia dolor doloribus facere eum libero repudiandae, quisquam, deserunt facilis magni error! Vero.
</p>
</body>
</html>

过渡

 

触发过渡

伪类触发  :hover  :focus  ....
媒体查询   @media
JS
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>过渡实例</title>
<style>
.item {
display: inline-block;
width: 100px;
height: 100px;
border: 1px solid #ccc;
text-align: center;
line-height: 100px;
border-radius: 50px;
font-size:30px;
cursor:pointer;
color:#f66700; /*过渡*/
transition: transform 1s;
} .item:hover {
transform: rotate(360deg)
}
</style>
</head>
<body>
<h1>同志</h1>
<hr> <div class="list">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</div>
<div class="item">6</div>
<div class="item">7</div>
<div class="item">8</div>
</div>
</body>
</html>

过渡实例

 

相关属性

transition-property  指定要过渡的属性 用,隔开。默认是 all
transition-duration 过渡持续时间
transition-timing-function 过渡线性效果 默认 ease
transition-delay   过渡延迟
transition:property timing-function duration delay
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>纯CSS实现下拉菜单</title>
<style>
* {
padding: 0;
margin: 0;
}
body {
font:14px "Microsoft YaHei",sans-serif;
}
ul {
list-style: none;
}
.container {
margin: 0 auto;
width: 1000px;
} .nav {
/*margin-top: 60px;*/
width: 100%;
height: 40px;
line-height: 40px;
background: #333;
} /*一级菜单*/ /*该选择器会选择 所有li*/
.nav li {
float: left;
position: relative;
} /*一级菜单*/
.nav li a {
display: block;
width: 100px;
text-align: center;
color: #fff;
text-decoration: none;
} /*二级菜单*/
.nav li ul li a {
color: #333;
}
.nav li ul li {
/*覆盖前面设置 */
float: none;
}
.nav li ul {
/*border: 1px solid #ccc;
border-top: none;*/
background: #fff;
/*二级菜单先隐藏*/
/*display: none;
*/
/*绝对定位*/
position: absolute;
left:0;
top:; overflow: hidden;
height: 0px; /*过渡*/
transition: height .5s;
} /*划过那个li 哪个li就变红*/
.nav li:hover {
background: red;
}
.nav li:hover ul{
/* display: block;*/
height: 160px;
} /*设置banner*/
.banner img {
width: 100%;
}
</style>
</head>
<body> <div class="nav">
<div class="container">
<ul>
<li><a href="#">首页</a></li>
<li>
<a href="#">博客</a>
<ul>
<li><a href="#">同志博客</a></li>
<li><a href="#">小同志博客</a></li>
<li><a href="#">老同志博客</a></li>
<li><a href="#">大同志博客</a></li>
</ul>
</li>
<li>
<a href="#">论坛</a>
<ul>
<li><a href="#">同志论坛</a></li>
<li><a href="#">红色论坛</a></li>
<li><a href="#">黄色论坛</a></li>
<li><a href="#">绿色论坛</a></li>
</ul>
</li>
<li><a href="#">关于我们</a></li>
<li>
<a href="#">举报我们</a>
<ul>
<li><a href="#">涉黄</a></li>
<li><a href="#">涉黑</a></li>
<li><a href="#">涉赌</a></li>
<li><a href="#">涉毒</a></li>
</ul>
</li>
</ul>
</div>
</div> <div class="banner">
<img src="../../dist/images_one/meinv02.jpg" alt="">
</div>
</body>
</html>

导航-下拉菜单

3.8 CSS3动画

关键帧

@keyframes 动画名字 {
   0% {
       
  }
   20% {
       
  }
   40% {
       
  }
   100% {
       
  }
}

相关CSS属性

animation-name  指定动画的名字
animation-duration 动画的执行时间
animation-timing-function 执行效果速度  
animation-delay   延迟
animation-iteration-count   循环 次数  infinite(无限)
animation-direction:  alternate (正向 反向 交替)\ reverse(反向)
animation-play-state: running / paused
animation 复合属性
 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CSS3动画</title>
<style> /*关键帧的语法*/
@keyframes myanimate{
from {
background: red;
width:200px;
} 50% {
width:400px;
} to {
background: green;
width:600px;
}
} .box {
width: 200px;
height: 200px;
border: 2px dashed orange; animation-name: myanimate;
animation-duration: 1s; /*动画持续时间*/
animation-timing-function: linear;
animation-delay: 0s;
animation-iteration-count: infinite; /*无限循环*/
animation-direction: alternate; /*多次循环的时候,一次正向动画,一次反向动画*/ animation-play-state: paused; animation: myanimate 2s linear 2 alternate;
} .box:hover {
animation-play-state: running;
}
</style>
</head>
<body> <div class="box"></div> </body>
</html>

css3动画

css3 变换、过渡效果、动画的更多相关文章

  1. CSS3:变换和动画

    <html> <style> .container{ -webkit-perspective: 800; -webkit-perspective-origin: 50% 40% ...

  2. css3 3D变换和动画

    3D变换和动画 建立3D空间,transform-style: preserve-3d perspective: 100px; 景深 perspective-origin:center center ...

  3. CSS3中的动画效果记录

    今天要记录的是CSS3中的三种属性transform.transition以及animation,这三个属性大大提升了css处理动画的能力. 一.Transform 变形 CSS中transform ...

  4. CSS3中的动画

    CSS3中的动画包括两种: Transition(过渡) Animation(动画) 这两种方法都可以让元素动起来,功能类似,但是稍有区别: Transition只定义某一个元素的开始状态和结束状态 ...

  5. CCS3的过渡、变换、动画以及响应式布局、弹性布局

    CSS3 过渡 .变换.动画 在没有CSS3之前,如果页面上需要一些动画效果,要么你自己编写 JavaScript,要么使用 JavaScript 框架(如 jQuery)来提高效率. 但是CSS3出 ...

  6. IT兄弟连 HTML5教程 CSS3属性特效 动画-animation

    CSS3属性中有关于制作动画的三个属性:Transform,Transition,Animation.前面已经介绍过Transform和Transition了,这里我们来学习Animation动画.通 ...

  7. CSS3中的动画功能(一)

    css3中的动画功能分为transitions功能和animations功能,这两种功能都可以通过改变css属性值来产生动画效果.今天带大家一起来看看css3动画功能中的transitions的用法. ...

  8. 如何制作css3的3d动画——以骰子旋转为例,详解css3动画属性

    首先先来看两个用css3实现的炫酷的3d动画效果 1 2 3 4 5   6 你没看错,这个炫酷的效果都是用css3实现的. 下面是动画实现所需要用到的几个css3属性. 1.perspective: ...

  9. css变换与动画详解

    举个栗子:--------元素整体居中.box{     position:absolute;top:50%;left:50%;    width:50px;    height:50px;    t ...

随机推荐

  1. 【UVA12779占位】Largest Circle

    几何题,希望有时间回来解决掉.

  2. HihoCoder 1508 : 剑刃风暴(占位)

    描述 主宰尤涅若拥有一招非常厉害的招式——剑刃风暴,“无论是战士还是法师,都害怕尤涅若的武士刀剑技”. 现在战场上有N名敌对英雄,他们的位置分别为(Xi, Yi),而剑刃风暴的伤害范围是一个半径为R的 ...

  3. Unix高级环境编程

    [07] Unix进程环境==================================1. 进程终止    atexit()函数注册终止处理程序.    exit()或return语句:    ...

  4. eclipse的工程里的*.properties文件默认以unicode的编码形式显示

    今天发现导入eclipse的工程里的*.properties文件无法显示中文,是unicode的编码形式显示的. 原因是Eclipse的.properties文件的默认编码为iso-8859-1. 选 ...

  5. Docker运行MongoDB及Redis及ssh端口映射远程连接

    Docker运行MongoDB及Redis及ssh端口映射远程连接 本节内容简介 在本实验里我们将通过完成 MongoDB 和 Redis 两个容器来学习Dockerfile及Docker的运行机制. ...

  6. IOS远程推送证书的制作步骤

    今天还在看环信的使用方法,在环信的官网上发现了这组制作远程推送证书的一组图片,正好之前本人没有写过关于远程证书的笔记,这里要写一篇博文,整理一下远程推送证书的制作流程,尽管如此,本篇博文依然是作者原创 ...

  7. CodeForces 1098E. Fedya the Potter

    题目简述:给定长度为$n \leq 5\times 10^4$的序列$a_1, a_2, \dots, a_n \leq 10^5$.将$\gcd(a_l, a_{l+1}, \dots, a_r) ...

  8. CCF 201509-3 模板生成系统 (STL+模拟)

    问题描述 成成最近在搭建一个网站,其中一些页面的部分内容来自数据库中不同的数据记录,但是页面的基本结构是相同的.例如,对于展示用户信息的页面,当用户为 Tom 时,网页的源代码是 而当用户为 Jerr ...

  9. fitnesse(gradle构建)安装步骤

    1.安装jdk.ant.gradle(参考http://www.cnblogs.com/274914765qq/p/4401525.html) 2.下载Fitnesse https://github. ...

  10. Python小爬虫,用Python3.X编写

    import urllib.request # 导入urlib.request模块import re # 导入re模块 # 获得每一页的网址并返回def get_url(pageNumber): ne ...