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>
相关推荐
Z***u65931 分钟前
前端性能测试实践
前端
xhxxx35 分钟前
prototype 是遗产,proto 是族谱:一文吃透 JS 原型链
前端·javascript
倾墨36 分钟前
Bytebot源码学习
前端
用户938169125536039 分钟前
VUE3项目--集成Sass
前端
S***H2831 小时前
Vue语音识别案例
前端·vue.js·语音识别
啦啦9118861 小时前
【版本更新】Edge 浏览器 v142.0.3595.94 绿色增强版+官方安装包
前端·edge
蚂蚁集团数据体验技术2 小时前
一个可以补充 Mermaid 的可视化组件库 Infographic
前端·javascript·llm
LQW_home2 小时前
前端展示 接受springboot Flux数据demo
前端·css·css3
q***d1732 小时前
前端增强现实案例
前端·ar
IT_陈寒2 小时前
Vite 3.0 重磅升级:5个你必须掌握的优化技巧和实战应用
前端·人工智能·后端