• 图片在父元素里面水平垂直居中


    <!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>

    </head>
    <style>
    .img_wrap{
    500px;
    height: 300px;
    border: 1px dashed #ccc;
    display: table-cell;
    vertical-align: middle;
    text-align: center;
    }

    img{

    height:auto;

    }
    </style>
    <body>

    <div class="img_wrap">
      <img src="https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1438475101,354016904&fm=58">
    </div>
    </body>

    </html>

    第二种》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》》

    <!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>

    </head>

    <body>

    <div class="pic"><img src="https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1438475101,354016904&fm=58" alt=""></div>

    <div class="pic"><img src="https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2201558756,12364836&fm=111&gp=0.jpg" alt=""></div>

    </body>

    </html>

    <style>

    .pic { 120px;height: 120px;margin: 40px auto;border: 1px solid #ccc;text-align: center;padding: 5px; }

    .pic:before { content: "";display: inline-block;height: 100%;vertical-align: middle; 0; }

    .pic img { max- 120px; max-height: 120px;vertical-align: middle; }

    </style>

    第三种图片不变形用背景实现

    <!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>

    </head>

    <body>

    <div class="pic"></div>

    </body>

    </html>

    <style>

    .pic {
    height: 300px;
    300px;
    background-repeat: no-repeat!important;
    background-position: center center!important;
    background-size: cover!important;
    background: url(https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1438475101,354016904&fm=58);
    }

    </style>

  • 相关阅读:
    vc生产垃圾清理
    完整的.h宏定义
    vs 2017 boost 安装目录 非安装
    cdlinux
    TryEnterCriticalSection
    go get 升级所有
    delphi win7 and high path
    本机激活Qemu网络配置 之桥接 win 10 2019 LTSC
    archlinux alsa安装,音量设置和音量信息保存
    windows搭建gcc开发环境(msys2) objdump
  • 原文地址:https://www.cnblogs.com/MagicZhao123/p/7252692.html
Copyright © 2020-2023  润新知