html - 输入字段在样式化组件中未正确设置动画
问题描述
我有以下样式组件 css。
const InputWrapper = styled.div`
position: relative;
direction: rtl;
`;
const Input = styled.input`
width: 70px;
direction: ltr;
color: #7795ca;
font-size: 1em;
box-sizing: border-box;
padding: 16px 20px 12px 57px;
transition: width 0.4s ease-in-out;
border-top: 0px solid #000;
border-right: 0 solid #000;
border-bottom: 2px solid #ffffff;
border-left: 0 solid #000;
background-color: #234ba5;
cursor: pointer;
z-index: 10;
&::-webkit-input-placeholder {
color: #7795ca;
}
&:focus {
width: 100%;
outline: none;
cursor: text;
}
`;
const Icon = styled.span`
display: block;
position: absolute;
width: 17px;
height: 20px;
top: 14px;
right: 30px;
cursor: pointer;
background-image: url(${searchIcon});
background-repeat: no-repeat;
&:active ~ ${Input} {
width: 100%;
}
`;
如您所见,我在输入元素聚焦时向输入元素添加了一些 css 过渡,效果很好。但是我还想要的是在 Icon 处于活动状态但不起作用时为输入设置动画。
下面是我的组件。
const Search = () => {
return (
<InputWrapper>
<Icon></Icon>
<Input type='text' name='Search' placeholder='Search all news' className='search' />
</InputWrapper>
);
}
我在下面创建了一个沙箱
https://codesandbox.io/s/zealous-margulis-rqveo?file=/src/App.js
解决方案
推荐阅读
- c# - 如何将 LiteDB 查询结果输出为字符串?
- python - 根据 python 中具有许多参数的现有函数中的一个自由参数创建一个可调用函数
- python - 如何在熊猫中划分一组连续的两行
- android - 从 Laravel 后端触发对 Android Studio 的自动响应
- jenkins - 如何使用jenkins版本号插件每天重置内部版本号1在版本中使用
- julia - 有哪些方法可以从 Julia 中的给定序列创建具有给定维度的数组?
- excel - 我的代码没有返回预期值(VBA)
- html - 正则表达式在包含所需文本的 html 表中选择一行
- java - 我可以在 Java 的类注释中调用方法吗?
- c++ - iostream 等效于 snprintf(NULL, 0, format_string, args...)