特殊布局方式(宽度可变的正方形,三角形,垂直居中)

宽度可变的正方形

padding-bottom和定位配合 实现宽度可变的正方形,要设两个div
css

.box{
				position: relative;
				width: 30%;
				padding-bottom: 30%;
				background: red;
				/*overflow: hidden;*/
				
			}
			.position-box{
				position: absolute;
				text-align: center;
				top: 0;
				right: 0;
				left: 0;
				bottom: 0;
				
			}
			.position-box img{
				height: 100%;
			}

html

<div class="box">
			<div class="position-box">
				<img src="img/et-4_4f05e68.png"/>
			</div>			
		</div>

运行截图
在这里插入图片描述

画三角形

宽跟高设为0,左右边框设为全头名,上边框不需要(注释),
设置三角形 transparent全透明色彩
css

.triangle{
				width: 0px;
				height: 0px;
				/*border-top: 50px solid #FF0000;*/
				border-bottom: 50px solid royalblue;
				border-left: 50px solid transparent;
				border-right: 50px solid transparent;
			}
			

html

<div class="triangle"></div>

运行截图
在这里插入图片描述

垂直居中

使用两个盒子嵌套 第一个 属性是 display:table 子元素的属性是display:table-cell,同时两个盒子都要vertical-align: middle;
css

.main{
				display: table;
				vertical-align: middle;
				width:300px;
				height: 300px;
				background: cornflowerblue;
			}
			.main-box{
				display: table-cell;
				vertical-align: middle;
				width: 100px;
				height: 100px;	
			}

html

<div class="main">
			<div class="main-box">
				<label>111</label>
			</div>
		</div>

运行截图
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值