zoukankan      html  css  js  c++  java
  • 盒模型布局

    盒模型布局

    1、盒模型布局基本介绍

    • 布局方位:margin-left、margin-right、margin-top、margin-bottom

    • 影响自身布局:margin-left、margin-top

    • 影响兄弟布局:margin-right、margin-bottom

    • 正向 / 反向:正值 / 负值

    2、margin布局坑位

    • 很多语义标签具有默认margin

    • 父子标签margin-top重叠取大者

    • 兄弟标签margin-bottom、margin-top重叠取大者

    =====================================================================================================================================

    笔记:

    <!DOCTYPE html>
    <html>
    <head>
    	<meta charset="UTF-8">
    	<title>盒模型布局</title>
    	<style>
    		/*做页面必备reset操作*/
    		html, body {
    			margin: 0
    		}
    		.box, .wrap {
    			 200px;
    			height: 200px;
    			background-color: red;
    		}
    		.wrap {
    			background: orange;
    		}
    		/*影响自身布局*/
    		/*.box {
    			margin-top: 30px;
    			margin-left: 100px;
    		}*/
    		/*影响兄弟布局*/
    		/*margin-bottom影响上下兄弟,尽量别对margin-right进行设置*/
    		/*margin-right影响左右兄弟,尽量别对margin-bottom进行设置*/
    		.box {
    			/*margin-bottom: 30px;*/
    			margin-right: 100px;
    		}
    
    		/*display:显示方式*/
    		/*块:block*/
    		/*内联:inline*/
    		/*内联块:inline-block*/
    		.box, .wrap {
    			display: inline-block;
    			/*vertical-align: top;*/
    		}
    
    		
    		/*兄弟坑*/
    		/*盒模型布局坑只出现在和margin-top相关的地方*/
    		.s1, .s2 {
    			 100px;
    			height: 100px;
    			background-color: pink;
    		}
    		/*重叠取大值*/
    		.s1 {
    			margin-bottom: 30px;
    		}
    		.s2 {
    			margin-top: 40px;
    		}
    		
    		/*父子坑*/
    		.sup {
    			 200px;
    			height: 200px;
    			background-color: cyan;
    		}
    		.sub {
    			 100px;
    			height: 100px;
    			background-color: orange;
    		}
    		/*父子top重叠,取大值*/
    		.sup {
    			margin-top: 50px;
    		}
    		.sub {
    			margin-left: 50px;
    		}
    		/*解决盒模型经典布局坑*/
    		/*1.将父级固定*/
    		.sup {
    			/*border-top: 1px solid black;*/
    			/*border-top: 1px solid transparent;*/
    			/*保证显示区域 200*200 */
    			/*height: 199px;*/
    		}
    		.sub {
    			/*margin-top: 50px;*/
    		}
    		/*2.通过padding*/
    		.sup {
    			padding-top: 50px;
    			height: 150px;
    		}
    
    		
    	</style>
    </head>
    <body>
    	<div class="box"></div>
    	<div class="wrap"></div>
    
    	<!-- 坑 -->
    	<section class="s1">1</section>
    	<section class="s2">2</section>
    
    	<div class="sup">
    		<div class="sub"></div>
    	</div>
    </body>
    </html>
    

      

  • 相关阅读:
    jquery ajax 后台响应成功,返回正确json但不执行success方法,执行error的问题
    bootstrap轮播组件,大屏幕图片居中效果
    mouseover和mouseout事件在鼠标经过子元素时也会触发
    vertical-align的深入学习
    小技巧
    css字体大小设置em与rem的区别
    子元素的margin-top影响父元素原因和解决办法
    JavaScript随机打乱数组
    JavaScript 获取当月天数
    javaScript 的option触发事件
  • 原文地址:https://www.cnblogs.com/zhangpang/p/9720686.html
Copyright © 2011-2022 走看看