简单方便的CSS盒子多个边框
可乐狼 2012-01-17
主流浏览器都支持,前和后的伪元素(所有主要浏览器),我们可以利用这种效应优势。当然,也有替代品,包括使用盒子阴影,以及增加额外的标记页面,然而这是最干净的解决方案。(经测试在我的傲游3的IE模式下没效果)
- <!DOCTYPE html>
- <html lang=”en“>
- <head>
- <meta charset=”utf-8“>
- <title>Multi-Borders</title>
- <style>
- body { background: #d2d1d0; }
- #box {
- background: #f4f4f4;
- border: 1px solid #bbbbbb;
- width: 200px;
- height: 200px;
- margin: 60px auto;
- position: relative;
- }
- #box:before {
- border: 1px solid white;
- content: ”;
- width: 198px;
- height: 198px;
- position: absolute;
- }
- #box:after {
- content: ”;
- position: absolute;
- width: 196px;
- height: 196px;
- border: 1px solid #bbbbbb;
- left: 1px; top: 1px;
- }
- </style>
- </head>
- <body>
- <div id=”box“></div>
- </body>
- </html>


