zoukankan      html  css  js  c++  java
  • 元素居中的一种特殊方法

    通过给需要居中的元素加入如下属性:使用此种方法,该元素会相对第一个具有定位环境的父元素居中

    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    margin: auto;

    示例代码:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
        <style>
            .fat{
                width: 500px;
                height: 500px;
                border: solid 1px black;
                position: relative;
            }
            .sub{
                width: 100px;
                height: 100px;
                border: solid 1px red;
                position: absolute;
                left: 0;
                top: 0;
                bottom: 0;
                right: 0;
                margin: auto;
            }
        </style>
    </head>
    <body>
        <div class="fat">
            <div class="sub"></div>
        </div>
    </body>
    </html>

  • 相关阅读:
    6.5 列出当前目录所有文件
    6.4 协程写文件
    6.3 写文件
    6.2 创建空目录
    6.1 os 获取文件状态
    5.13 json
    es2016
    短路原理
    fexbox
    vue @
  • 原文地址:https://www.cnblogs.com/huwt/p/10947197.html
Copyright © 2011-2022 走看看