一、圆角效果 border-radius
使用方法:
border-radius:10px; /* 所有角都使用半径为10px的圆角 */
border-radius: 5px 4px 3px 2px; /* 四个半径值分别是左上角、右上角、右下角和左下角,顺时针 */
不要以为border-radius的值只能用px单位,你还可以用百分比或者em。
1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 8 <title>border-radius</title> 9 <style> 10 #box { 11 width: 100px; 12 height: 100px; 13 background-color: aquamarine; 14 border-radius: 5px; 15 } 16 17 #box1 { 18 width: 100px; 19 height: 100px; 20 background-color: red; 21 border-radius: 50%; 22 } 23 24 #box2 { 25 width: 100px; 26 height: 100px; 27 background-color: blue; 28 border-radius: 5px 10px 20px 30px; 29 } 30 31 #box3 { 32 width: 50px; 33 height: 100px; 34 background-color: coral; 35 border-radius: 50px 0px 0px 50px; 36 } 37 </style> 38 </head> 39 40 <body> 41 <h4>为正方形添加圆角效果</h4> 42 <div id="box"></div> 43 44 <br> 45 46 <h4>实心圆</h4> 47 <div id="box1"></div> 48 49 <br> 50 51 <h4>为正方形4个角分别添加不同的圆角幅度</h4> 52 <div id="box2"></div> 53 54 <br> 55 56 <h4>半圆</h4> 57 <div id="box3"></div> 58 </body> 59 60 </html>
二、边框阴影 box-shadow
box-shadow是向盒子添加阴影。支持添加一个或者多个。
语法:
box-shadow: X轴偏移量 Y轴偏移量 [阴影模糊半径] [阴影扩展半径] [阴影颜色] [投影方式];
参数介绍:
注意:inset 可以写在参数的第一个或最后一个,其它位置是无效的。
1、阴影模糊半径与阴影扩展半径的区别
阴影模糊半径:此参数可选,其值只能是为正值,如果其值为0时,表示阴影不具有模糊效果,其值越大阴影的边缘就越模糊;
阴影扩展半径:此参数可选,其值可以是正负值,如果值为正,则整个阴影都延展扩大,反之值为负值时,则缩小;
2、X轴偏移量和Y轴偏移量值可以设置为负数
注意:如果添加多个阴影,只需用逗号隔开即可
1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 8 <title>box-shadow</title> 9 <style> 10 #box { 11 width: 100px; 12 height: 100px; 13 box-shadow: 4px 2px 6px #333333; 14 } 15 16 #box1 { 17 width: 100px; 18 height: 100px; 19 box-shadow: 4px 2px 6px #333333 inset; 20 } 21 22 #box2 { 23 width: 100px; 24 height: 100px; 25 box-shadow: 4px 2px 6px #f00, 26 -4px -2px 6px #000, 27 0px 0px 12px 5px #33cc00 inset 28 } 29 30 #box3 { 31 width: 100px; 32 height: 100px; 33 box-shadow: -4px 2px 6px #333333; 34 } 35 36 #box4 { 37 width: 100px; 38 height: 100px; 39 box-shadow: 4px -2px 6px #333333; 40 } 41 </style> 42 </head> 43 44 <body> 45 46 <h3>外阴影</h3> 47 <div id="box"></div> 48 49 <h3>内阴影</h3> 50 <div id="box1"></div> 51 52 <h3>添加多个阴影&l