CSS
Allen 2021-12-03 09:50:04 3517 0 0 0 0
Css,HTML,CSS控制图片不改变原比例居中显示,图片超出DIV部分隐藏

html部分

          <h2>图片预览</h2>
          <div class="md-camera" @click="previewImg">
              <img class="cameraImg" :src="preImgSrc" alt>
          </div>

css部分

 .md-camera {
        height: 340px;
        width: 100%;
        border-radius: 10px;
        border: 1px dashed rgba(208, 205, 207, 1);
        overflow: hidden;
        box-sizing: border-box;
        display: flex;
        justify-content: center;
        align-items: center;

        .cameraImg {
          width: 100%;
         }
}


html部分

 
    <div class="mask" v-if="preStatus">
      <span @click="closePre">×span>
      <div class="pre" v-if="showIV">
        <img class="preImg" :src="preImgSrc" alt>
      div>
    div>

css部分

 //   蒙版 -- 预览
  .mask {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    background: rgba(0, 0, 0, 1);
    .px2rem(10);
    padding: 0 @px2rem;

    span {
      display: block;
      .px2rem(80);
      color: #ffffff;
      font-size: @px2rem;
    }

    span {
      position: absolute;
      .px2rem(20);
      left: @px2rem;
      // top: @px2rem;
    }

    .pre {
      width: 100%;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      .px2rem(360);
      margin-top: -@px2rem;
      margin: auto;

      .preImg {
        width: 100%;
        height: 100%;
        display: block;
      }

      img {
        width: auto;
        height: auto;
        max-width: 100%;
        max-height: 100%;
        display: block;
      }
    }
  }

【版權聲明】
本文爲原創,遵循CC 4.0 BY-SA版權協議!轉載時請附上原文鏈接及本聲明。
原文鏈接:https://tdlib.com/am.php?t=ybXukNuQH1M2
Tag: Css HTML
我也要發一個   ·   返回首頁   ·   返回[CSS]   ·   前一個   ·   下一個
歡迎評論
未登錄,
請先 [ 註冊 ] or [ 登錄 ]
(一分鍾即可完成註冊!)
返回首頁     ·   返回[CSS]   ·   返回頂部