zoukankan      html  css  js  c++  java
  • 面试:div水平垂直居中方案--img自适应

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>垂直居中--图片自适应宽高</title>
            <style type="text/css">
                /* 方法一 定位 为了看效果就加上了背景 宽高*/ 
                .wrap{
                    position: relative;
                    width: 200px;
                    height: 200px;
                    background: #000;
                }
                .box{
                    position: absolute;
                    top: 50%;
                    left: 50%;
                    background: #999; 
                    width: 100px;
                    height: 100px;
                    transform: translate(-50%,-50%);
                }
                /* 方法二 flex布局 */
                .wrap{
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    width: 200px;
                    height: 200px;
                    background: #000;
                }
                .box{
                    background: #999;
                    width: 100px;
                    height: 100px;
                }
                /* 图片自适应宽高 */
                img{
                    max-width: 100%;
                    max-height: 100%;
                }
            </style>
        </head>
        <body>
            <div class="wrap">
                <div class="box">
                    <img src="https://f11.baidu.com/it/u1=2936607031&u2=3595029289&fm=76" >
                </div>
            </div>
        </body>
    </html>
  • 相关阅读:
    【项目】项目17
    【项目】项目16
    【项目】项目15
    【项目】项目14
    【项目】项目13
    【项目】项目12
    【项目】项目11
    【项目】项目10
    【项目】项目9
    【项目】项目8
  • 原文地址:https://www.cnblogs.com/lhl66/p/13817848.html
Copyright © 2011-2022 走看看