border 就是边框, border 的功勋卓越表现在 border 属性可以在图像构建, 体验优化以及网友布局大放异彩.
border-width 不支持百分比值
border-style 类型
border-style:none; 默认值是 none
border-style: solid 实线边框
border-style: dashed 虚线边框
border-style: inset 内凹
border-style:outset 外凸
border-style: groove 沟槽
border-style: ridge 山脊
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>dome</title>
- <style>
- div{
- width: 100px;
- height: 100px;
- color: #cd7777;
- border: 2px dashed;
- }
- .box:before{
- border-top:10px solid;
- }
- .box:after{
- border-left: 10px solid;
- }
- .box:hover{
- color: #b70000;
- }
- </style>
- </head>
- <body>
- <div class="box"></div>
- </body>
- </html>
border 与透明边框技巧
等腰三角形
- span{
- width: 0;
- border: 10px solid;
- border-color: #cd0000 transparent transparent;
- }
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>dome</title>
- <style>
- .box{
- padding: 5px;
- width: 120px;
- height: 40px;
- background-color: #cd7777;
- position: relative;
- margin: 100px;
- }
- .box:before{
- content:'';
- width: 0;
- border-width: 10px 20px;
- border-style:solid;
- border-color: transparent #cd7777 #cd7777 transparent;
- left: -40px;
- top: 20px;
- position: absolute;
- }
- </style>
- </head>
- <body>
- <div class="box">
- hello world!
- </div>
- </body>
- </html>
使用 border-left 和负 margin-left 等高实例
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>dome</title>
- <style>
- #nav{
- border-left: 150px solid #333;
- background-color: #cd7777;
- }
- /* 需要清除浮动但不能使用 overflow*/
- #nav:after{
- content:'';
- display: block;
- clear: both;
- }
- #nav>nav{
- text-align: center;
- width: 150px;
- margin-left: -150px;
- float: left;
- }
- .nav{
- color: #ffffff;
- line-height: 40px;
- }
- .module{
- line-height: 40px;
- }
- </style>
- </head>
- <body>
- <div id="nav">
- <nav><h3 class="nav"> 导航一 </h3></nav>
- <section><div class="module"></div></section>
- </div>
- </body>
- </html>
来源: http://www.qdfuns.com/note/49226/f4991bbf47937706a33abbe974f49baa.html