SYSTEM
边框样式
src/content/notes/system/边框样式.md 边框样式
单个边框
-
单个边框 border:边框 border-top: 上边框 border-left: 左边框 border-bottom: 底边框 border-right: 右边框
-
无边框,当border值为none时,可以让边框不显示
div { width: 200px; height: 200px; border: none; } -
圆角
通过使用[
border-radius]属性设置盒子的圆角,虽然能分别设置四个角,但是通常我们使用一个值,来设置整体效果
#d1{
/*设置所有边框*/
/*border: 5px solid black;*/
/*设置上边框*/
border-top: 5px solid black;
/*设置左边框*/
border-left: 5px double red;
/*设置右边框*/
border-right: 5px dotted blue;
/*设置下边框*/
border-bottom: 5px dashed pink;
width: 150px;
height: 150px;
}
#d2{
border: 5px solid red;
/*设置边框的弧度*/
border-radius: 25px;
width: 150px;
height: 150px;
}
<body>
<div id="d1"></div>
<br/>
<div id="d2"></div>
</body>
边框轮廓
轮廓outline:是绘制于元素周围的一条线,位于边框边缘的外围,可起到突出元素的作用
- 属性值:double:双实线 dotted:圆点 dashed:虚线 none:无
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>样式演示</title>
<style>
input{
outline: dotted;
}
</style>
</head>
<body>
用户名:<input type="text"/> <br/>
</body>
</html>

盒子模型
模型介绍
盒子模型是通过设置元素框与元素内容和外部元素的边距,而进行布局的方式。

- element : 元素。
- padding : 内边距,也有资料将其翻译为填充。
- border : 边框。
- margin : 外边距,也有资料将其翻译为空白或空白边。
边距
内边距、边框和外边距都是可选的,默认值是零。在 CSS 中,width 和 height 指的是内容区域的宽度和高度。
-
外边距 单独设置边框的外边距,设置上、右、下、左方向:
margin-top margin-right margin-bottom margin-left-
margin: auto /*浏览器自动计算外边距,具有居中效果。*/ -
一个值
/* 所有 4 个外边距都是 10px */ margin:10px; -
两个值
margin:10px 5px;/* 上外边距和下外边距是 10px*/ margin:10px auto;/*右外边距和左外边距是 5px */ -
三个值
/* 上外边距是 10px,右外边距和左外边距是 5px,下外边距是 15px*/ margin:10px 5px 15px; -
四个值
/*上外边距是 10px,右外边距是 5px,下外边距是 15px,左外边距是 20px*/ /*上右下外*/ margin:10px 5px 15px 20px;
-
-
内边距 与外边距类似,单独设置边框的内边距,设置上、右、下、左方向:
padding-top padding-right padding-bottom padding-left
布局
-
基本布局
<style> div{ border: 2px solid blue; } .big{ width: 200px; height: 200px; } .small{ width: 100px; height: 100px; margin: 30px;/* 外边距 */ } </style> <div class="big"> <div class="small"> </div> </div
-
增加内边距会增加元素框的总尺寸
<style> div{ border: 2px solid blue; } .big{ width: 200px; height: 200px; padding: 30px;/*内边距 */ } .small{ width: 100px; height: 100px; } </style>