*首先要清楚的是,box-shadow的形状会随着border-radius变化。下面的例子可以证明:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> div{ width: 200px; height: 200px; border-radius: 20px; background: #f00; margin: 100px; outline: 10px solid #00f; } .div3{ outline: none; box-shadow: 0 0 0 10px green; } </style> </head> <body> <div class="div3"></div> </body> </html>
效果:
*而实现内圆角边框(外边框为直角)就可利用以上特性(box-shaodw填充outline和border之间的空白),代码如下:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> div{ width: 200px; height: 200px; border-radius: 20px; background: #f00; margin: 100px; outline: 10px solid #00f; } .div1{ box-shadow: 0 0 0 10px #ff0; } .div2{ box-shadow: 0 0 0 10px #00f; } </style> </head> <body> <div class="div1"></div> <div class="div2"></div> </body> </html>
div1 效果:
div2效果:
喜欢请推荐,转载请标明出处。