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>

  • 相关阅读:
    linux命令查询网站
    UTC(世界协调时间)时区和各个时区时间的转换
    dev-c++ 中写完源文件生成exe程序怎么避免运行闪退?
    numpy和time计时程序
    进化算法之粒子群算法和Matlab实现(多维)
    tf.config:GPU 的使用与分配(转载)
    限制TensorFlow只在CPU上运行的方法
    Python重要学习链接
    SpringCloud 之 Nacos 注册配置中心
    Jenkins 自动化部署入门详细教程
  • 原文地址:https://www.cnblogs.com/eaysun/p/3678465.html
Copyright © 2011-2022 走看看