reactjs - 如何在 Box 模型中创建带有样式组件的切换器?
问题描述
我想创建切换器以与样式化组件做出反应。当我单击切换器时,它不会关闭或打开切换器。切换器已创建,但即使我在代码中使用检查作为伪元素它也不是活动的。我的代码在这里
import React from 'react'
import Box from 'app/components/Box'
import css from '@styled-system/css'
export const FeatureFlagPage = () => {
return (
<Box position='relative'>
<Box
as='input'
id='checkbox'
typeof='checkbox'
opacity='0'
zIndex={1}
borderRadius={15}
width={42}
height={26}
css={css({
'::checked': {
backGround: '#4fbe79',
'::after': {
content: '""',
display: 'block',
borderRadius: '50%',
width: '18px',
height: '18px',
marginLeft: '21px',
transition: '0.2s',
},
},
})}
/>
<Box
as='label'
position='absolute'
top='0'
left='0'
width='42px'
height='26px'
borderRadius='15px'
backgroundColor='#bebebe'
cursor='pointer'
css={css({
'::after': {
content: '""',
display: 'block',
borderRadius: '50%',
width: '18px',
height: '18px',
margin: '3px',
backGround: '#ffffff',
boxShadow: '1px 3px 3px 1px rgba(0, 0, 0, 0.2)',
transition: '0.2s',
},
})}
/>
</Box>
)
}
实际上我无法解决如何在我的伪元素被称为检查后使用+来制作这样的代码。
&:checked + ${CheckBoxLabel} {
background: #4fbe79;
&::after {
content: "";
display: block;
border-radius: 50%;
width: 18px;
height: 18px;
margin-left: 21px;
transition: 0.2s;
}
}
解决方案
推荐阅读
- npm - 如何将 PostCSS PreCSS 插件添加到项目中
- kotlin - Kotlin:未解决的参考:使用,
- javascript - JS Script Uncaught ReferenceError: $ is Not Defined When Loading HTML File to Server
- skaffold - 如何从 skaffold 中 docker hub 的 docker 映像运行 docker 容器?
- mysql - 更改列默认值后是否需要重建索引?
- java - 删除双向链表中指定节点后的节点。(递归)
- mirth - LabDaq - 发送附件
- html - CSS轮播只一遍又一遍地显示最后一张图片
- r - 有没有办法创建一个使用多个参数的函数,并为每个参数独立运行相同的函数?
- android - 仅通过 XML android 旋转可绘制