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>
    

    在这里插入图片描述

  • 相关阅读:
    userAgent判断当前设备类型
    h5+css3最简单的图片飞入以及淡入淡出效果
    ruby的form中常用的控件
    初识swipe.js
    后缀为7z的文件解码
    python all()函数
    flask web表单
    flask过滤器
    flask学习笔记1.21
    py学习笔记1.13、1.14
  • 原文地址:https://www.cnblogs.com/jianjie/p/12127136.html
Copyright © 2011-2022 走看看