Tags: / Posted in 前端研究

简单方便的CSS盒子多个边框

2012-01-17

主流浏览器都支持,前和后的伪元素(所有主要浏览器),我们可以利用这种效应优势。当然,也有替代品,包括使用盒子阴影,以及增加额外的标记页面,然而这是最干净的解决方案。(经测试在我的傲游3的IE模式下没效果)

  1. <!DOCTYPE html>
  2. <html lang=”en
  3. <head> 
  4.     <meta charset=”utf-8>
  5.     <title>Multi-Borders</title>
  6.     <style> 
  7.         body { background: #d2d1d0; }
  8.         #box {
  9.             background: #f4f4f4;
  10.             border: 1px solid #bbbbbb;
  11.             width: 200px;
  12.             height: 200px;
  13.             margin: 60px auto;
  14.             position: relative;
  15.         }
  16.         #box:before {
  17.             border: 1px solid white;
  18.             content: ”;
  19.             width: 198px;
  20.             height: 198px;
  21.             position: absolute;
  22.         }
  23.         #box:after {
  24.             content: ”;
  25.             position: absolute;
  26.             width: 196px;
  27.             height: 196px;
  28.             border: 1px solid #bbbbbb;
  29.             left: 1px; top: 1px;
  30.         }
  31.     </style> 
  32. </head> 
  33. <body> 
  34.     <div id=”box“></div>  
  35. </body>
  36. </html> 

发表评论