css布局总结

目录

 

1.盒子模型

1.盒子模型的重要属性---border

2.浮动布局----float

3.定位布局----position

4.溢出效果----overflow

5.缩放-----zoom

6.弹性盒子-----display属性


1.盒子模型

div又叫盒子模型,在本质上是一个盒子用于封装周围的HTML元素。包括边框、边距、填充和内容。

1.盒子模型的重要属性---border

  • border------指定代表某一元素的盒子边框如何呈现。

 

border-width规定边框的宽度thin定义细的边框
medium默认值,定义中等边框
thick定义粗的边框
length允许您自定义边框宽度
border-style规定边框的样式

 

none定义无边框
hidden与none相同,应用于表时除外,在表中,hidden用于解决边框冲突
dotted定义点状边框
dashed定义虚线边框
solid定义实线
double定义双线
groove定义3D凹槽边框
ridge定义3D垄状边框
inset定义3Dinset边框
outset定义3Doutset边框
border-color规定边框颜色color_name规定颜色值为颜色名称的边框颜色
hex_number规定颜色值为十六进制的边框颜色
rgb_number规定颜色值为rgb代码的边框颜色
transparent默认值,边框为透明
<head>
	<meta charset="UTF-8">
	<title>布局</title>
	<style type="text/css">
	.top{
		width: 300px;
		height: 40px;
		border-width: thick;
		border-style: double;
		border-color: blue;
	}
		</style>
</head>
<body>
	<div class="top">
	</div>
</body>

效果展示:

  • border-botton------把下边框的所有属性设置到一个声明中。

border-bottom-width

属性设置元素的下边框的宽度

border-bottom-style

设置元素下边框的样式

border-bottom-color

设置元素的下边框的颜色

border-bottom-left-radius 

定义左下角边框的形状

 border-bottom-right-radius

定义右下角边框的形状
  • border-image----插入图片

border-image-source用在边框的图片的路径。
border-image-slice图片边框向内偏移。
border-image-width图片边框的宽度。
border-image-outset边框图像区域超出边框的量。
border-image-repeat图像边框是否应平铺(repeated)、铺满(rounded)或拉伸(stretched)。

 

  • border-left和border-right

border-left规定左边框border-left-width规定左边框的宽度。
border-left-style规定左边框的样式。
border-left-color规定左边框的颜色。
border-right规定右边框border-right-width规定右边框的宽度。
border-right-style规定右边框的样式。
border-right-color规定右边框的颜色。
  • border-top----规定上边框
border-top-width规定上边框的宽度。
border-top-style规定上边框的样式。
border-top-color规定上边框的颜色。
border-top-left-radius定义左上角边框的形状。
border-top-right-radius定义右下角边框的形状。

注释:border-top-left-radius和border-top-right-radius 属性的长度值和百分比值定义四分之一椭圆(定义外部边框边缘的边角形状)的半径(radii)。第一个值是水平半径,第二个值是垂直半径。如果省略第二个值,则复制第一个值。如果长度为零,则边角为方形,而不是圆形。水平半径的百分比值参考边框盒的宽度,而垂直半径的百分比值参考边框盒的高度。

  • 其他属性
border-collapse设置表格的边框是否被合并为一个单一的边框,还是像在标准的 HTML 中那样分开显示。
border-radius一个简写属性,用于设置四个 border-*-radius 属性。
border-spacing设置相邻单元格的边框间的距离(仅用于“边框分离”模式)。
<head>
	<meta charset="UTF-8">
	<title>布局</title>
	<style type="text/css">
	.top{
		width: 700px;
		height: 100px;
		border-width: thick;
		border-style: double;
		border-color: blue;
		background-image: url(10.jpg);
		border-image-repeat: repeated;
		border-bottom-left-radius: 2em;
		border-spacing: 10px 50px;
	}
		</style>
</head>
<body>
	<div class="top">
	</div>
</body>

效果展示:

2.浮动布局----float

       float 属性定义元素在哪个方向浮动。以往这个属性总应用于图像,使文本围绕在图像周围,不过在 CSS 中,任何元素都可以浮动。浮动元素会生成一个块级框,而不论它本身是何种元素。如果浮动非替换元素,则要指定一个明确的宽度;否则,它们会尽可能地窄。假如在一行之上只有极少的空间可供浮动元素,那么这个元素会跳至下一行,这个过程会持续到某一行拥有足够的空间为止。

none不浮动
left左浮动,会对后面元素产生影响
right右浮动

浮动布局的时候,左浮动会造成后面元素的布局错乱的现象,我们需要用clear清除浮动。

none默认值,允许两边有浮动
left不允许有左浮动
right不允许有右浮动
both不允许两边有浮动
<head>
	<meta charset="UTF-8">
	<title>布局</title>
	<style type="text/css">
	#all{
		width: 400px;
		height: 200px;
		border-style: solid;
		border-color: #956;
	}
	.top{
		width: 100px;
		height: 100px;
		background-color: red;
		float: left;
	}
	.mid{
		width: 100px;
		height: 100px;
		background-color: blue;
		float: right;
	}
	.foot{
		width: 100px;
		height: 100px;
		background-color: green;
	}
		</style>
</head>
<body>
<div id="all">
	<div class="top">第一个div</div>
	<div class="mid">第二个div</div>
	<div class="foot">第三个div</div>
</div>
</body>

效果展示:

注释:因为第一个div是左浮动,第三个div没有浮动,所以第三个div在第一个div下面。

3.定位布局----position

static(默认值) 静态定位
absolute 绝对定位 :将对象从文档流分离出来,通过设置top、left、right、bottom这四个
方向的值进行定位(相较于父级的定位),如果没有这样的父级,默认的父级是body
relative相对定位:对象不从文档流里面分离,通过设置top、left、right、bottom这四个方向
的值进行定位(相较于自身的定位)
<head>
	<meta charset="UTF-8">
	<title>布局</title>
	<style type="text/css">
	#all{
		width: 400px;
		height: 200px;
		border-style: solid;
		border-color: #956;
	}
	.top{
		width: 100px;
		height: 100px;
		background-color: red;
		position: relative;
	}
	.mid{
		width: 100px;
		height: 100px;
		background-color: blue;
	}
	.foot{
		width: 100px;
		height: 100px;
		background-color: green;
	}
		</style>
</head>
<body>
<div id="all">
	<div class="top">第一个div</div>
	<div class="mid">第二个div</div>
	<div class="foot">第三个div</div>
</div>
</body>

效果展示:

4.溢出效果----overflow

visible默认值,溢出没有被剪裁,内容在元素框外渲染
hidden溢出被剪裁,其余内容将不可见
scroll 溢出被剪裁,同时添加滚动条以查看其余内容
auto与 scroll 类似,但仅在必要时添加滚动条(总是显示滚动条)
<head>
	<meta charset="UTF-8">
	<title>布局</title>
	<style type="text/css">
	.top{
		width: 100px;
		height: 100px;
		border-width: thick;
		border-style: double;
		border-color: blue;
		background-image: url(10.jpg);
		border-image-repeat: repeated;
	    overflow: scroll;
	}
		</style>
</head>
<body>
	<div class="top">
	</div>
</body>

效果展示:

5.缩放-----zoom

    zoom的语法结构:    zoom : number 百分比

<head>
	<meta charset="UTF-8">
	<title>布局</title>
	<style type="text/css">
	.top{
		width:600px;
		height: 100px;
		border-width: thick;
		/* border-style: double; */
		border-color: blue;
		background-image: url(10.jpg);
		border-image-repeat: repeated;
/* 	    overflow: scroll; */
        zoom:0.5;
	}
		</style>
</head>
<body>
	<div class="top">
	</div>
</body>

效果展示:

6.弹性盒子-----display属性

利用display属性定义flex(设置属性的时候是在父元素上设定的)

属性  
flex-direction定义盒子显示方式row(默认值)从左到右显示
row-reverse从右到左显示
column从上到下显示
column-reverse从下到上显示
flex-wrap定义换行方式wrap必要的时候自动换行
nowrap(默认值)不换行
wrap-reverse需要的时候换行以相反方向换行
flex-flow同时设置显示方式和换行方式(结合flex-direction和flex-wrap)flex-flow: flex-direction flex-wrap|initial|inherit;
<style type="text/css">
	.all{
		display: flex;
		flex-direction:row-reverse;
		width: 400px;
		height: 200px;
		border: 0px solid red;
	}
	.all>div{
		width: 100px;
		height: 100px;
		background-color: #e42ff3;
	}
	</style>

效果展示:

其他属性:

属性  
justify-content对齐弹性容器的项目,当项目不占用主轴上所有可用空间时。center居中对齐
flex-start默认值,左对齐
flex-end末端对齐
space-around每个盒子都设置空格
space-between盒子与盒子之间有空格
align-items为弹性容器内的项目指定默认对齐方式。 垂直方向上的居中
flex-start容器顶部对齐
flex-end容器底部对齐
stretch拉伸盒子适应容器,前提是盒子没有设置高度
baseline基线对齐
align-content修改 flex-wrap 属性的行为。它与 align-items 相似,但是它不对齐弹性项目,而是对齐弹性线。center容器之间打包
flex-start盒子顶部对齐
flex-end盒子底部对齐
stretch拉伸盒子适应容器
space-between每行均匀分布
space-around每行均匀分布在弹性容器中,两端各占一半。
flex-grow规定在相同的容器中,项目相对于其余弹性项目的增长量。(没有设置盒子高宽的时候可以设置大小)
flex-shrink固定在相同的容器中,项目相对于其余弹性项目的收缩量。
flex-basis规定弹性项目的初始长度。
align-self指定弹性容器内所选项目的对齐方式。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值