*首先要清楚的是,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效果:
喜歡請推薦,轉載請標明出處。
