以正圆为基础设置圆角
border-radius:将元素设为圆角
当为一个值时 会设置四个角
当两个值时 会以左上右下、右上左下。
当三个值时 会以左上、右上左下、右下。
当四个值时 会以左上、右上、右下、左下顺时针顺序分别设置四个圆角
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 200px;
height: 100px;
background-color: orange;
float: left;
margin-right: 20px;
}
.div1 {
border-radius: 20px;
}
.div2 {
border-radius: 20px 50px;
}
.div3 {
border-radius: 20px 50px 60px;
}
.div4 {
border-radius: 10px 20px 30px 40px;
}
</style>
</head>
<body>
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<div class="div4"></div>
</body>
以椭圆为基础设置圆角
border-radius:x半径/y半径
当值为 30px/60px时会显示椭圆形 第一个值代表水平,第二个值代表垂直
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 200px;
height: 100px;
border-radius: 30px/50px;
background-color: orange;
}
</style>
</head>
<body>
<div class="div"></div>
</body>
盒子阴影
外阴影
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 200px;
height: 100px;
background-color: orange;
box-shadow: 5px 10px 10px red;
}
</style>
</head>
<body>
<div class="div"></div>
</body>
内阴影
<style>
div {
width: 200px;
height: 100px;
background-color: orange;
box-shadow: 5px 10px 10px red inset;
}
</style>
同时设置内外阴影
<style>
div {
width: 200px;
height: 100px;
background-color: orange;
box-shadow: 5px 10px 10px red inset, 5px 10px 10px blue;
}
</style>
box-shadow:x偏移 y偏移 模糊半径 阴影颜色 //inset,x偏移 y偏移 模糊半径 阴影颜色 ;
inset内阴影样式值 可写可不写
逗号分隔 可同时设置内外阴影
边框图片
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 200px;
height: 100px;
border: 20px solid transparent;
border-image: url(./img/border.png) 28 28 round;
}
</style>
</head>
<body>
<div class="div"></div>
</body>
边框所引入的原图
border-image:url 切片偏移 边界宽度 超出量 重复平铺;
border-image-source:使用图片(url路径获取图片)作为边框
border-image-slice:图片向内偏移 切片
border-image-width:边框图片的宽度
border-image-outset:边框图像区域超出边框的量 不常用
border-image-repeat:图片是否平铺(repeat)铺满(round)拉伸(stretch)
背景图
背景图填充
<style>
div {
width: 200px;
height: 100px;
float: left;
margin-right: 20px;
border: 10px solid transparent;
padding: 20px;
background: #ccc url(./img/flower_small.gif) no-repeat;
}
.div1 {
background-origin: border-box;
}
.div2 {
background-origin: padding-box;
}
.div3 {
background-origin: content-box;
}
</style>
<body>
<div class="div1">
内容内容内容内容内容<br>
</div>
<div class="div2">
内容内容内容内容内容<br>
</div>
<div class="div3">
内容内容内容内容内容<br>
</div>
</body>
背景色填充位置
<style>
div {
width: 300px;
height: 100px;
float: left;
margin-right: 20px;
border: 10px solid transparent;
padding: 20px;
background-color: #ccc;
}
.div1 {
background-clip: border-box;
}
.div2 {
background-clip: padding-box;
}
.div3 {
background-clip: content-box;
}
</style>
<body>
<div class="div1">
内容内容内容内容内容内容内容内容内容<br>
内容内容内容内容内容内容内容内容内容<br>
内容内容内容内容内容内容内容内容内容<br>
</div>
<div class="div2">
内容内容内容内容内容内容内容内容内容<br>
内容内容内容内容内容内容内容内容内容<br>
内容内容内容内容内容内容内容内容内容<br>
</div>
<div class="div3">
内容内容内容内容内容内容内容内容内容<br>
内容内容内容内容内容内容内容内容内容<br>
内容内容内容内容内容内容内容内容内容<br>
</div>
</body>
background: 不分先后顺序 空格隔开;
background-image:url() 引入图片
background-position: 图片位置
background-repeat:图片平铺
background-size:图片大小 contain(等比例放大到盒子的宽度) cover(等比例撑满整个盒子,超出隐藏)
background-origin:背景图片的覆盖区域(内边距区域(padding-box)、边框区域(border-box)、内容区域(content-box))
background-clip:背景开始绘制的位置 默认(border-box)、从内边距开始绘制背景色(padding-box)、从内容开始绘制背景色(content-box)
动画
<style>
div {
width: 10px;
height: 100px;
background-color: red;
transition: all 5s;
transition: all 3s steps(3);
transition-timing-function: cubic-bezier(0, .51, .32, 1.39);
}
div:active {
width: 100px;
height: 200px;
margin-left: 300px;
background-color: blue;
transform: rotate(360deg);
}
</style>
<body>
<div>
</div>
</body>
transition:
ease — 慢慢开始 中间加速 慢慢结束(默认)
linear — 相同速度过渡效果
ease-in — 缓慢开始的过度效果
ease-out — 缓慢结束的过渡效果
cubic-bezier(n,n,n,n) — 允许在三次贝塞尔函数中定义自己的值
steps(n)分为n个步骤;
transform-origin — 以某个点进行转换left/right/top/bottom
自定义动画
@keyframes 动画名{
from{}
to{}
}
@keyframes 动画名{
0%{}
100%{}
}
调用动画
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.k {
width: 500px;
height: 500px;
border: 1px solid red;
position: relative;
}
.circle {
width: 70px;
height: 70px;
border-radius: 50%;
background: radial-gradient(#eee, orange);
position: absolute;
top: 100px;
left: 200px;
animation: jump 2s ease infinite;
}
.ellipse {
width: 40px;
height: 30px;
background: radial-gradient(rgb(204, 203, 203), rgb(211, 211, 211));
position: absolute;
top: 350px;
left: 215px;
border-radius: 50%;
z-index: -999;
box-shadow: 0 0 20px rgb(138, 138, 138);
animation: circleShadow 2s ease infinite;
}
/* 小球跳跃 */
@keyframes jump {
0% {
transform: scale(1);
top: 100px;
}
50% {
transform: scale(.7);
top: 300px;
}
100% {
transform: scale(1);
top: 100px;
}
}
/* 阴影 */
@keyframes circleShadow {
0% {
opacity: 0.3;
transform: scale(1);
}
50% {
opacity: 1;
transform: scale(1.5);
}
100% {
opacity: 0.3;
transform: scale(1);
}
}
</style>
</head>
<body>
<div class="k">
<div class="circle"></div>
<div class="ellipse"></div>
</div>
</body>
animattion: 简写;
animation-name:动画名; —— 添加动画
animation-duration:动画时间; —— 设置动画事件
animation-fill-mode: ;——设置动画结束后的样式
none:默认不会应用任何样式
forwards:保留最后一帧的样式
backwards:返回第一帧
both:遵循向前和向后的规则
animation-delay:2s;——动画延时时间 为负数时 是当动画执行多长时间
animation-iteration-count:infinite;——播放次数 infinite 循环播放
animation-direction: ;——播放顺序
reverse 倒着播放动画
alternate 先向前播放,然后向后
alternate-reverse 先向后播放,在向前播放