zoukankan      html  css  js  c++  java
  • 0060 translate、margin 实现绝对定位的盒子 水平居中、垂直居中

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            div {
                position: relative;
                 300px;
                height: 300px;
                background-color: pink;
                /* 1. 我们tranlate里面的参数是可以用 % */
                /* 2. 如果里面的参数是 %, 移动的距离是 盒子自身的宽度或者高度来对比的 */
                /* 这里的 50% 就是 50px 因为盒子的宽度是 100px */
                /* transform: translateX(50%); */
            }
            
            p {
                position: absolute;
                top: 50%;
                left: 50%;
                 100px;
                height: 100px;
                background-color: lightseagreen;
                /* margin-top: -100px;
                margin-left: -100px; */
                /* translate(-50%, -50%)  盒子往上走自己高度的一半   */
                transform: translate(-50%, -50%);
            }
            
            span {
                /* translate 对于行内元素是无效的 */
                transform: translate(300px, 300px);
            }
            /* 我的补充 */
            i {
                display: inline-block;
                 100px;
                height: 30px;
                line-height: 30px;
                background-color: lightgreen;
                text-align: center;
                transform: translate(30px, 30px);
            }
        </style>
    </head>
    
    <body>
        <div>
            <p></p>
        </div>
        <span>123</span>
        <i>哈哈哈</i>
    </body>
    
    </html>
    

    在这里插入图片描述

  • 相关阅读:
    phonegap(cordova)环境配置
    Mobile Web调试工具Weinre (reproduce)
    webstorm快捷键
    学习笔记:乘性操作符之求模
    消息队列原理笔记
    运维wiki
    supervisor 文档
    redis 批量删除 keys
    linux命令和工具
    urllib urllib2学习笔记
  • 原文地址:https://www.cnblogs.com/jianjie/p/12127136.html
Copyright © 2011-2022 走看看