zoukankan      html  css  js  c++  java
  • 水平垂直居中的四种方法

    居中面试的方法

    一、带宽高的类型

    <style>
    			.father{
    				 500px;
    				height: 500px;
    				background-color: blue;
    				position: relative;
    			}
    			.son{
    				position: absolute;
    				 200px;
    				height: 200px;
    				background-color: red;
    			top: 50%;
    			left: 50%;
    
    	margin-top: -100px;
    	margin-left: -100px;
    			border: 5px solid black;
    			}
    		</style>
    			<body>
    		<div class="father">
    			<div class="son"></div>
    		</div>
    	</body>
    
    		<style>
    			.father{
    				 500px;
    				height: 500px;
    				background-color: blue;
    				position: relative;
    			}
    			.son{
    				position: absolute;
    				 200px;
    				height: 200px;
    				background-color: red;
    				border: 5px solid black;
                                    top: 0;
    				left: 0;
    				right: 0;
    				bottom: 0;
    				margin: auto;
    			}
    		</style>
    		
    			<body>
    		<div class="father">
    			<div class="son"></div>
    		</div>
    	</body>
    

    二、不带宽高

    		<style>
    			.father{
    				 500px;
    				height: 500px;
    				background-color: blue;
    				position: relative;
    			}
    			.son{
    				position: absolute;
    				background-color: red;
    				left: 50%;
    				top: 50%;
    				transform: translate(-50%,-50%);
    			
    			}
    		</style>
    			<body>
    		<div class="father">
    			<div class="son">box</div>
    		</div>
    	</body>
    
    	<style>
    		.father{
    			 500px;
    			height: 500px;
    			background-color: blue;
    			display: flex;
    justify-content: center;	
    			align-items: center;
    		}
    		.son{
    			background-color: red;
    		}
    	</style>
    </head>
    <body>
    	<div class="father">
    		<div class="son">box111</div>
    	</div>
    </body>
  • 相关阅读:
    MongoDB 基本概念
    MongoDB 设置参数
    MongoDB 操作数据库
    MongoDB 目录分析、基础命令、参数设置
    Windows下MongoDB的下载安装、环境配置
    MongoDB 简介
    SQL与NoSQL
    es6 箭头函数(arrow function) 学习笔记
    WebPack 简明学习教程
    vue自定义指令
  • 原文地址:https://www.cnblogs.com/AFBF/p/14604201.html
Copyright © 2011-2022 走看看