css新特性

上章我们介绍了css的基础,内容,各个特点,现在我们一起看看新增的东西

一、css新增选择器

1.1层次选择器

E F:选择器E的所有后代F

E>F:选择E的子代F

E+F:选择E的相邻兄弟F(这里最好定义一个类选择器,或者id选择器)

E~F:选择E的所有兄弟F 不包括自己
<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			/* 后代选择器 E F */
			.box p{
				background-color: black;
			}
			/* 子代选择器 E>F */
			ul>li{
				background-color: pink;
			}
			/* 相邻兄弟选择器E+F */
			.one+p{
				background-color: yellow;
			}
			/* 通用兄弟选择器E~F */
			.one~p{
				background-color: red;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<p class="one">1</p>
			<p>2</p>
			<p>3</p>
			<ul>
				<li></li>
				<li></li>
				<li></li>
				<li></li>
			</ul>
		</div>
	</body>

在这里插入图片描述

1.2层次选择器

	E[id]:选择具有Id属性的标签E
	E[id=“first”]:选择id为first的标签E
	E[class*=“links”]:选择class包含links的标签E
	E[href^="http"]:选择href以http开头的标签E
	E[href$="jpg"]:选择href以jpg结尾的标签E
<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.demo a {
				float: left;
				display: block;
				height: 50px;
				width: 50px;
				border-radius: 10px;
				text-align: center;
				background: #aac;
				color: blue;
				font: bold 20px/50px Arial;
				margin-right: 5px;
				text-decoration: none;
			}
			
			/* 选择有id属性的a标签 */
			a[id]{
				background-color: red;
			}
			
			/* 选择id=first的a标签 */
			a[id="first"]{
				background-color: #0000FF;
			}
			
			/* 选择class包含links的标签a */
			a[class*="links"]{
				background-color: pink;
			}
			
			/* 选择href以http开头的标签a */
			a[href^="http"]{
				background-color:magenta;
			}
			/* 选择href以.jpg结尾的标签a */
			a[href$=".jpg"]{
				background-color:black;
			}
		</style>
	</head>
	<body>
		<p class="demo">
			<a href="http://www.baidu.com" class="links item first" id="first">1</a>
			<a href="" class="links active item" title="test website" target="_blank">2</a>
			<a href="sites/file/test.html" class="links item">3</a>
			<a href="sites/file/test.png" class="links item"> 4</a>
			<a href="sites/file/image.jpg" class="links item">5</a>
			<a href="efc" class="links item" title="website link">6</a>
			<a href="/a.pdf" class="links item">7</a>
			<a href="/abc.pdf" class="links item">8</a>
			<a href="abcdef.doc" class="links item">9</a>
			<a href="abd.doc" class="linksitem last" id="last">10</a>
		</p>
	</body>

在这里插入图片描述

1.3结构伪类选择器

	E F:first-chid:E的第一个孩子F(必须是第一个)
	E F:last-child:E的最后一个孩子F(必须是最后一个)
	E F:nth-chid(n) E的第n个孩子F
	E F:nth-child(even/odd):选择E的偶数行F或则奇数行F
	div:empty 选择空元素
 **常用:**
	E F:first-of-type:E的第一个孩子类型F
	E F:last-of-type:E的最后一个孩子类型F      
	E F:nth-of-type(n) E的第n个孩子类型F
	E F:nth-of-type(even/odd):选择E的偶数行类型F或则奇数行类型F
	F:not([class="active"]):选择除了class=active的元素F
<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			/* wrapper的第一个孩子p */
			.wrapper p:first-child{
				background-color: green;
			}
			/* wrapper的最后一个孩子p */
			.wrapper p:last-child{
				background-color: green;
			}
			
			/* wrapper的第3个孩子p */
			.wrapper p:nth-child(3){
				background-color: green;
			}
			/* wrapper的偶数行p 2,4*/
			.wrapper p:nth-child(even){
				background-color: pink;
			}
			/* wrapper的奇数行p 1,3,5*/
			.wrapper p:nth-child(odd){
				background-color: red;
			}
			
			/* 3*0+1  3*1+1 */
			/* 1,4行变色 */
			.wrapper p:nth-child(3n+1){
				background-color: blue;
			}
			/* ========================================= */
			.list li:first-of-type{
				background-color: red;
			}
			.list li:last-of-type{
				background-color: red;
			}
			.list li:nth-of-type(3){
				background-color: red;
			}
			.list li:nth-of-type(even){
				background-color: mediumvioletred;
			}
			/* 选择空元素div */
			div:empty{
				height: 50px;
				border: 1px solid;
				background-color: #000000;
			}
			
			/* 否定选择器:not([class="active"] )*/
			/* 选择除了class=active的p元素 */
		.wrapper p:not([class="active"]){
				border: 3px solid;
			}
		</style>
	</head>
	<body>
		<div class="wrapper">
			<!-- <h3>666</h3> -->
			<p class="active">1</p>
			<p class="active">2</p>
			<p>3</p>
			<p>4</p>
			<p>5</p>
		</div>
		<div></div>
		<ul class="list">
			<h3>6666</h3>
			<li>1</li>
			<li>2</li>
			<li>3</li>
			<li>4</li>
			<li>5</li>
		</ul>
	</body>

在这里插入图片描述

1.4、动态伪类选择器

a:link:链接访问时
a:visited:访问后
a:hover:悬浮离开
a:actived:激活时
:focus  光标聚焦时
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			/* 动态伪类:a:link->a:visited->a:hover->a:active  :focus焦点 */
			#user:focus{
				/* border: 3px dotted red; */
				outline: none;
				border: none;
				background-color: pink;
				text-indent: 2em;
			}
			
			/* UI元素伪类选择器::checked  :disabled  :enabled */
			/* 选择被选中的单选框 */
			input[type="radio"]:checked{
				width: 20px;
				height: 20px;
			}
			/* 选择禁用的文本框 */
			input[type="text"]:disabled{
				background-color: blue;
			}
			/* 选择可用的文本框 */
			input[type="text"]:enabled{
				background-color: red;
			}
		</style>
	</head>
	<body>
		<input type="text" name="" id="user" value="" /><br>
		<input type="radio" name="gender" id="" value="female" checked/><input type="radio" name="gender" id="" value="male" /><br>
		<input type="text" name="" disabled value="" />
	</body>

在这里插入图片描述

二、css新增样式

1.1、边框:

	border-radius:圆角
	border-image:边框背景图片
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			.box1 {
				width: 300px;
				height: 300px;
				background-color: red;
				/* 圆角半径:顺时针上右下左 */
				/* border-radius:100px/80px 80px 60px 40px; */
				/* border-radius:20px; */
				/* 圆 */
				/* border-radius:150px; */
				border-radius: 50%;
			}

			.box2 {
				width: 300px;
				height: 150px;
				background-color: red;
				/* border-radius: 150px 150px 0 0; */
				border-radius: 0 0 150px 150px;
			}

			/* transform 延哪个轴旋转 */
			.box3 {
				width: 150px;
				height: 300px;
				background-color: red;
				border-radius: 0 150px 150px 0;
				transform: rotateY(180deg);
			}
		</style>
	</head>
	<body>
		<div class="box1"></div>
		<div class="box2"></div>
		<div class="box3"></div>
	</body>

在这里插入图片描述

1.2、盒子:

	box-sizing:border-box 拯救布局
	box-shadow:color x y 模糊半径 扩展半径 [inset]
	标准盒:width+padding+border+margin
	怪异盒:(conten+padding+border)(width)+margin
<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
		/* 	标准盒模型:content(width)+padding+border+margin
			怪异盒模型:(content+padding+border=width)+margin */
			.box{
				width: 300px;
				height: 300px;
				background-color: red;
				padding: 50px;
				/* border: 10px solid; */
				/* 拯救布局 */
				box-sizing: border-box;  /* 怪异盒模型 */
			/* 	box-sizing: content-box; 标准盒模型,默认 */
			
			    /* 盒子阴影:box-shadow:阴影颜色 X轴 y轴 模糊半径 扩展半径 内阴影(inset) */
				box-shadow:black 15px 15px 20px 10px inset;
			}
		</style>
	</head>
	<body>
		<div class="box"></div>
	</body>

在这里插入图片描述

1.3、文本:

    text-shadow:color x y 模糊半径
	@font-face{font-family:name;src:url()},自定义字体

1.4、背景:

	background-image:url(),url()    多重背景图片
	linear-gradient(to top left,color1,color2 20%,...)   线性渐变
	radial-gradient(circle  size  at center,color1,color2 20%,...)    径向渐变
	repeating-linear-gradient/repeating-radial-gradient   重复渐变
<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			/* 多重背景图片 */
			.box1{
				width: 300px;
				height: 200px;
				background:url(img/chui.png),url(img/poll.png);
				background-repeat:no-repeat,no-repeat;
				background-position: 0 0,50px 0;
			}
			
			/* 线性渐变 */
			.box2{
				width: 300px;
				height: 300px;
				/* linear-gradient(渐变的方向,渐变的颜色)
				渐变的方向:to bottom left */
				background-image:linear-gradient(to top right,red 0%,yellow 30%,blue 80%,green);
				background-image:-moz-linear-gradient(to top right,red 0%,yellow 30%,blue 80%,green);
				background-image:-webkit-linear-gradient(to top right,red 0%,yellow 30%,blue 80%,green);
				background-image:-ms-linear-gradient(to top right,red 0%,yellow 30%,blue 80%,green);
				/* 重复渐变 */
				/* background-image:repeating-linear-gradient(to top right,red 0%,yellow 10%,blue 20%,green 30%) */
				
			}
		</style>
	</head>
	<body>
		<div class="box1"></div>
		<div class="box2"></div>
	</body>

在这里插入图片描述

2.1、2d变形transform:

	translate(x,y)  位移,单位px
	skew(x,y) 倾斜,单位deg
	rotate(x,y,z),旋转,单位deg
	scale(x,y) 缩放,没有单位 倍数
	perspective:200px  透视,父级
	transform-origin:bottom/top/center/left/right/30% 50%   旋转轴心
	backface-visibility:hidden   背面不可见

因为这里是一个动图效果,感兴趣的小伙伴可以把代码复制一下然后鼠标悬浮到红色快上面看看效果,可以来回试试换换哦!

<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			body{
				perspective: 1000px;
			}
			.box{
				width: 200px;
				height: 200px;
				background-color: red;
			
				/* 过度效果 */
				transition: all 2s;
			}
			.box:hover{
				/* 2d位移 */
				/* transform: translateX(300px);
				transform: translateY(300px);
				transform: translate(300px); => translateX(300px)
				transform: translate(300px,300px); */
				/* 2d缩放 */
				/* transform: scaleX(2);
				transform: scaleY(2); */
				/* transform: scale(2);  =>transform: scale(2,2) */
				/* transform: scale(2,0.5); */
				/* 2d旋转 */
				/* transform: rotateX(180deg); */
				/* transform: rotateY(180deg);
				transform: rotateZ(180deg); */
				/* transform: rotate(180deg);=>transform: rotateZ(180deg); */
				/* 2d倾斜 */
				/* transform: skewx(90deg); */
				/* 综合设置: */
				transform: translate(300px,300px)  scale(0.5) rotate(180deg);
			}
			
		</style>
	</head>
	<body>
		<div class="box">帅哥</div>
	</body>

2.2、过渡:

transtion:all(过渡属性) 时间 速度 延迟时间

2.3、关键帧:

	  @keyframe name{from{}  to{}}
	@keyframe name{0%{}  50%{}  100%{}}

2.4、动画:

		animation:name  时间 速度  延迟时间  播放次数(infinite无限)    播放是否反向    最后停留位置
	   animation-play-state: paused;  暂停播放
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值