前端杂文之盒子始终属于上下左右居中位置

回顾flex布局
參看 https://www.cnblogs.com/hellocd/p/10443237.html

<div style="border: 1px red solid;display: flex;justify-content: space-around;">
			<div style="background: red;width: 200px;height: 200px;">
				<div style="background: blueviolet;width: 100px;height: 100px;"></div>
			</div>
			**回顾相对定位和绝对定位 相对定位和绝对定位**
			<div style="background: red;width: 200px;height: 200px; position: absolute;">
				<div style="background: blueviolet;width: 100px;height: 100px; position: relative;
					top: 50px;left: 50px;"></div>
			</div>
			
			<div style="background: red;width: 200px;height: 200px;">
				<div style="background: blueviolet;width: 100px;height: 100px;"></div>
			</div>
			
			<div style="background: red;width: 200px;height: 200px;">
				<div style="background: blueviolet;width: 100px;height: 100px;"></div>
			</div>					
		</div>

技巧一:盒子始终属于上下左右居中位置
在这里插入图片描述
如上图所示 我们想要一个盒子上下左右居中在屏幕中间,并且盒子高度和宽度是不固定的,我们可以这么做

<body class="parent">
		<form class="child">
		4444444444444444444444444444444444444444444
		444444444444444444444444444444444444444444444444444444
		444444444444444444444444444444444444444444444444444444		
		</form>
</body>
	<style>
		.parent{
			background: gainsboro;
		}
	.child{
			border: 1px red solid ;
			width: 500px;
			position: absolute;
			word-wrap: break-word; //超出宽度自动换行
		    top: 50%;
		    left: 50%;
		    //向X轴平移,填正数往右平移,填负数,往左平移
		    transform: translate(-50%, -50%);
	}
	</style>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值