zoukankan      html  css  js  c++  java
  • 怎么让块级元素水平和垂直都居中

    在我们平时用DIVCSS布局网页的时候,经常碰到就是如何让div块水平和垂直都居中的情况,今天,建站教程网就给大家提供两种方法:

    方式一:利用定位及负边距

    <!DOCTYPE html>
    <html>
        <head>
            <title>让块级元素水平和垂直都居中(方法一)</title>
            <meta charset="utf-8">
            <style>
                .wrapper {
                    height: 600px;
                    border: 1px solid red;
                    position: relative;
                }
                .box {
                    120px;
                    height: 120px;
                    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>

    方式二:利用margin居中的方法

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

  • 相关阅读:
    从浏览器输入URL到页面渲染的过程
    安全分析的几个好的工具网站的使用
    从一次渗透谈到linux如何反弹shell
    python 进行抓包嗅探
    MYSQL的索引和常见函数
    一篇博客搞定redis基础
    新型横向移动工具原理分析、代码分析、优缺点以及检测方案
    Java反序列化漏洞的挖掘、攻击与防御
    关于Memcached反射型DRDoS攻击分析
    spark未授权RCE漏洞
  • 原文地址:https://www.cnblogs.com/eaysun/p/3678465.html
Copyright © 2011-2022 走看看