一张网页可以理解为多个div盒子组成。让我们先了解CSS 的框模型 (Box Model)
框模型:元素框处理元素内容、内边距、边框 和 外边距 的方式
参考下图
div代码演示:
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>名字</title> <meta name="Keywords" content="关键词,关键词"> <meta name="Description" content=""> <style type="text/css"> *{margin:0;padding:0;} div{width:240px;height:240px;border:1px solid red;} .box{float:left;margin:100px 100px 0 100px;} .box_padding{float:left;padding:50px 50px 0 50px;} </style> </head> <body> <div class="box">我是一个有margin的div盒子</div> <div class="box_padding">我是一个有padding的div盒子</div> </body> </html>border代码演示:
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>border</title> <meta name="Keywords" content="关键词,关键词"> <meta name="Description" content=""> <!--css,js--> <style type="text/css"> *{margin:0;padding:0;} .demo_border{width:400px;height:300px;margin:50px auto;border:1px solid red;border-radius:8px;} .demo_border .one{width:300px;height:200px;margin:50px auto; border-right: dashed red; border-bottom: dotted red; border-left: double red; border-top: hidden red;} .demo_border .one .two{width:200px;height:100px;margin:50px auto; border-right:6px groove red; border-bottom:6px ridge red; border-left:6px inset red; border-top:6px outset red;} </style> </head> <body> <div class="demo_border"> <div class="one"> <div class="two"></div> </div> </div> </body> </html>
其实就是把圆角设置和div的宽度一样就可以了
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>圆</title> <meta name="Keywords" content="关键词,关键词"> <meta name="Description" content=""> <!--css,js--> <style type="text/css"> *{margin:0;padding:0;} .circle{width:200px;height:200px;border:1px solid green;border-radius:200px; margin:100px auto;background:green;} .circle .small{width:180px;height:180px;border:1px solid green; border-radius:180px;background:#fff;margin:10px auto;} </style> </head> <body> <div class="circle"> <div class="small"></div> </div> </body> </html>