指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

一直以来对相对定位和绝对定位的使用,有一点儿模糊,就是边界问题,今天通过一个例子证明了两个结论: 1.子级的宽高可以比父级的宽高大 2.不管父级设置border-sizing为什么,子级都是相对父级内边框定位的

<!DOCTYPE html>
<html>
<head>
	<title>相对定位和绝度定位的关系</title>
	<style type="text/css">
		.parent{
			width: 200px;
		    height: 300px;
		    display: block;
		    text-align: right;
		    background: #0056B1;
		    /*border: 20px solid #86C671;*/
		    /*box-sizing: border-box;*/
		    position: relative;
		}

		.child1{
			width: 50px;
		    height: 50px;
		    background-color: blue;
		}

		.child2{
			/*子级的宽高可以比父级的宽高大*/
			width: 400px;
		    height: 500px;

		    display: none;
		    text-align: right;
		    background: #CEF6FF;
		    /*border: 20px solid #F67539;*/
		    /*box-sizing: border-box;*/
		    position: absolute;


		    /*下面这个证明,不管父级设置border-sizing为什么,子级都是相对父级内边框定位的*/
sss
		    /*top: 0;
		    left: 100%;*/


			/*下面这个证明,子级定位的范围可以跑到父级定义的宽高的外面*/
		    right: 0;
		    top: 300px;
		    /*top: 310px;*/
		}
	</style>
</head>
<body>
<div class="parent">
	parent
	<div class="child1">child1</div>
	<div class="child2">child2</div>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.js"></script>
<script type="text/javascript">
	$(function(){
		$('.parent').click(function(event){
			$('.child2').css('display','none');
			event.stopPropagation();
		})

		$('.child1').click(function(event){
			$('.child2').css('display','block');
			event.stopPropagation();
		})
	});
</script>
</html>