文章目录
1. 圆角边框2. 盒子阴影3. 文字阴影1. 圆角边框
在CSS3 中,新增了圆角边框样式,这样我们的盒子就可以变圆角了。
border-radius 属性用于设置元素的外边框圆角。
语法:
radiu半径(圆的半径)原理:(椭)圆与边框的交集形成圆角效果:
注意:
参数值可以为数值或百分比的形式如果是正方形,想要设置为一个圆,把数值修改为高度或者宽度的一半即可,或者直接写为50%该属性是一个简写属性,可以跟四个值,分别代表左上角、右上角、右下角、左下角分开写:border-top-left-radius、border-top-right-radius、border-bottom-right-radius 和border-bottom-left-radius兼容性ie9+浏览器支持, 但是不会影响页面布局,可以放心使用.
示例:
<!DOCTYPE html><html lang="en"><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>.yuanxing {width: 200px;height: 200px;background-color: pink;/* border-radius: 100px; *//* 50%就是宽度和高度的一半 等价于100px */border-radius: 50%;}.juxing {width: 300px;height: 100px;background-color: pink;border-radius: 50px;}.radius {width: 200px;height: 200px;background-color: pink;border-radius: 10px 20px 30px 40px;}</style></head><body>1.圆形的做法:<div class="yuanxing"></div>2.圆角矩形的做法:<div class="juxing"></div>3.可以设置不同的圆角<div class="radius"></div></body></html>
2. 盒子阴影
CSS3 中新增了盒子阴影,我们可以使用box-shadow属性为盒子添加阴影。
语法:
注意:
默认的是外阴影(outset), 但是不可以写这个单词,否则造成阴影无效盒子阴影不占用空间,不会影响其他盒子排列。
示例:
<!DOCTYPE html><html lang="en"><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: 200px;background-color: pink;margin: 100px auto;}div:hover {box-shadow: 10px 10px 10px rgba(0, 0, 0, .3);}/* 原先盒子没有影子,当我们鼠标经过盒子就添加阴影效果 */</style></head><body><div></div></body></html>
3. 文字阴影
在CSS3 中,我们可以使用text-shadow 属性将阴影应用于文本。
语法:
示例:
<!DOCTYPE html><html lang="en"><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 {font-size: 50px;color: orangered;font-weight: 700;text-shadow: 5px 5px 6px rgba(0,0,0,.3);}</style></head><body><div>桃李不言,下自成蹊</div></body></html>
参考视频:/video/BV14J4114768?p=165