SCSS上传图片占位区域样式

_App.scss

css 复制代码
// 上传图片占位区域样式----------------------------------------
[theme="uploadImage"] {
    transition: 0.2s;
    position: relative;
    cursor: pointer;
    border-radius: 4px;
    /*居中填满*/
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;

    &::before {
        content: "按要求上传图片";
        transition: 0.2s;
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
        box-sizing: border-box;
        border: 1px dashed transparent;
        border-radius: 4px;
        background-color: #fafafa;
        color: #c6d1de;
        font-size: 20px;
        display: flex;
        justify-content: center;
        align-items: center;
        line-height: normal;
        animation: sg-animate-px 1s linear forwards;

        @keyframes sg-animate-px {
            0% {
                opacity: 0;
            }

            100% {
                opacity: 1;
            }
        }
    }

    &[style*="background"] {
        &::before {
            content: none!important;
        }
    }

    &:hover {
        &[style*="background"] {
            transform: scale(1.01);
        }

        &::before {
            color: #409eff;
            border-color: currentColor;
            background-color: #409eff11;
        }
    }

    &:active {

        &[style*="background"],
        &::before {
            transform: scale(0.99);
        }
    }
}

demo

html 复制代码
<template>
  <div :class="$options.name">
    <div
      class="uploadImage"
      theme="uploadImage"
      :style="imgFile ? { backgroundImage: `url('${imgFile}')` } : ``"
      @click="imgFile = `http://www.baidu.com/img/flexible/logo/pc/result@2.png`"
    />
  </div>
</template>
<script>
export default {
  name: `demo-uploadImage`,
  data() {
    return {
      imgFile: ``,
    };
  },
};
</script>
<style lang="scss" scoped>
.demo-uploadImage {
  .uploadImage {
    $width: 400;
    $height: 130;
    width: #{$width}px;
    height: #{$height}px;
    &::before {
      content: "#{$width} × #{$height}像素";
    }
  }
}
</style>
相关推荐
人工智能训练师3 小时前
Ubuntu22.04如何安装新版本的Node.js和npm
linux·运维·前端·人工智能·ubuntu·npm·node.js
Seveny073 小时前
pnpm相对于npm,yarn的优势
前端·npm·node.js
yddddddy4 小时前
css的基本知识
前端·css
昔人'4 小时前
css `lh`单位
前端·css
Nan_Shu_6146 小时前
Web前端面试题(2)
前端
知识分享小能手6 小时前
React学习教程,从入门到精通,React 组件核心语法知识点详解(类组件体系)(19)
前端·javascript·vue.js·学习·react.js·react·anti-design-vue
2501_918126917 小时前
用html5写一个flappybird游戏
css·游戏·html5
蚂蚁RichLab前端团队7 小时前
🚀🚀🚀 RichLab - 花呗前端团队招贤纳士 - 【转岗/内推/社招】
前端·javascript·人工智能
孩子 你要相信光7 小时前
css之一个元素可以同时应用多个动画效果
前端·css
huangql5207 小时前
npm 发布流程——从创建组件到发布到 npm 仓库
前端·npm·node.js