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>
    

      

  • 相关阅读:
    【css】怎么让Chrome支持小于12px 的文字
    java操作linux,调用shell命令
    20个非常有用的Java程序片段
    Java集合详解
    SVN使用指南
    利用SQL语句查询数据库中所有表
    HttpClient-03Http状态管理
    HttpClient-02连接管理
    HttpClient-01基本概念
    IDEA安装插件
  • 原文地址:https://www.cnblogs.com/zhangpang/p/9720686.html
Copyright © 2011-2022 走看看