zoukankan      html  css  js  c++  java
  • 块级元素水平,垂直居中的两种方式

    方式一: 利用margin

    <!DOCTYPE html>
    <html>
        <head>
            <title>块级元素水平,垂直居中</title>
            <meta charset="utf-8">
            <style>
            	.wrapper {
            		height: 600px;
            		border: 1px solid gray;
            	}
            	.box {
            		 100px;
            		height: 100px;
            		background: gold;
            		margin: 250px auto 0;
            	}
            </style>
        </head>
        <body>
    		<div class="wrapper">
    			<div class="box"></div>
    		</div>
        </body>
    </html>
    

     

    方式二,利用定位及负边距

    <!DOCTYPE html>
    <html>
        <head>
            <title>块级元素水平,垂直居中</title>
            <meta charset="utf-8">
            <style>
            	.wrapper {
            		height: 600px;
            		border: 1px solid gray;
            		position: relative;
            	}
            	.box {
            		 100px;
            		height: 100px;
            		background: gold;
            		position: absolute;
            		left: 50%;
            		top: 50%;
            		margin-left: -50px;
            		margin-top: -50px;
            	}
            </style>
        </head>
        <body>
    		<div class="wrapper">
    			<div class="box"></div>
    		</div>
        </body>
    </html>
    

      

  • 相关阅读:
    Qt 主窗口与子窗口之间传值
    Qt 如何使窗体初始最大化
    C++ strcmp与strncmp的比较
    Qt 状态栏(statusbar)的使用
    C++中的补零
    Qt QString转char[]数组
    PAT基础6-9
    PAT基础6-8
    PAT基础6-6
    PAT基础6-7
  • 原文地址:https://www.cnblogs.com/snandy/p/2768404.html
Copyright © 2011-2022 走看看