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>
相关推荐
妙码生花2 小时前
从 PHP 到 AI + Golang,程序员自救转型手记(十七):登录接口完善,登录页接口整合,解决跨域
前端·后端·ai编程
唐诗2 小时前
改 3 行配置,我的 Tauri dev 冷启动从 100 秒干到 4 秒
前端·客户端
SmartBoyW3 小时前
深入ECMAScript规范:彻底搞懂JS隐式类型转换与底层ToPrimitive机制
前端·javascript
牧艺3 小时前
Cursor Rules / Skills 分层设计:让 Agent 像「团队新同事」
前端·人工智能·cursor
光影少年3 小时前
react navite 跨端核心原理
前端·react native·react.js
monologues3 小时前
Vue 3 渲染器的核心秘密:从 VNode 创建到快速 Diff 算法
前端
奇奇怪怪的3 小时前
从开发到生产——生成优化、监控、安全与成本
前端
10share3 小时前
100行代码 模拟实现Vue 响应式系统
前端·vue.js
Heo3 小时前
Vite进阶用法详解
前端·javascript·面试
狂炫冰美式4 小时前
人均配了AI, 为什么公司还是没变快? 🤔 本质还是分布式系统问题
前端·后端·架构