【问题标题】:unwanted height animation on SVGSVG上不需要的高度动画
【发布时间】:2021-03-24 11:49:54
【问题描述】:

我正在制作一个表单,并使用 SVG 来创建边框中的间隙效果,以便我可以将占位符文本向上移动。目前,我将它放在具有绝对定位的边框上,然后将宽度设置为 0,然后当我需要出现间隙时,我将宽度设置为全宽。我遇到的问题不仅仅是对宽度进行动画处理,高度也在动画处理,这意味着在动画期间显示了一些背景,从而产生了一种奇怪的效果。这是 CSS:

.cutout {
    top: 6px;
    width: 0;
    height: 5px;
    min-height: 5px;
    max-height: 5px;
    transition: width 0.1s ease
}

...

.field:focus-within .cutout {
    width: 130px;
}

和 JSX:

import React, { Component } from 'react';
import '../css/input.css'
import cutout from '../img/cutout.svg';

class Input extends Component {
    render() {
        return (
            <label className="field body-font">
                <input name={this.props.name} type={this.props.type} autocorrect={this.props.autocorrect} id={this.props.id} required />
                <span className="placeholder" >{this.props.placeholder}</span>
                <img className="cutout" src={cutout} alt="" />
            </label>
        );
    }
}

export default Input;

当然,我要让它具有响应性,让它不仅适用于稍后关注输入的情况,而且我想让动画首先工作。有什么办法可以确保高度始终是 5px 无论如何

【问题讨论】:

    标签: html css animation svg


    【解决方案1】:

    没有看到你的html,你的问题不是很清楚,但是试着写:

    .field:focus-within .cutout {
        width: 130px;
        height: 5px;
    }
    

    【讨论】:

    • 我添加了那个,什么都没有,我将添加我的 HTML
    猜你喜欢
    • 1970-01-01
    • 2015-04-30
    • 2022-11-01
    • 2021-07-19
    • 2017-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    相关资源
    最近更新 更多