【发布时间】:2021-05-12 09:08:36
【问题描述】:
我在将来自外部 css 模块的自定义 css 应用到来自 Reactstrap 的输入时遇到问题。 所以我有以下代码:
<Input
className={'border-0 p-0'}
style={{
width: '150px',
height: '100px',
fontSize: '18px',
overflow: 'hidden',
resize: 'none',
backgroundColor: 'ffffff',
boxShadow: 'none',
marginTop: '-10px',
marginBottom: '10px'
}}
innerRef={register}
type={'textarea'}
readOnly
/>
现在可以使用内联样式,但是属性太多,我想将它们放在 scss 外部模块中,但它不起作用。
我试过style={styles.customCss} 但它不起作用,我的自定义样式没有应用。我也尝试过输入className={'border-0 p-0' && styles.customCss},但仍然无法正常工作。
有什么想法吗?
在我的 Css 外部文件中
.customCss {
width: '150px';
height: '100px';
font-size: '18px';
overflow: 'hidden';
resize: 'none';
background-color: 'ffffff';
box-shadow: 'none';
margin-top: '-10px';
margin-bottom: '10px'
}
在我的组件中我有
import React from 'react';
import { useForm } from 'react-hook-form';
import {
Container,
Row,
Col,
Label,
Input,
Button,
FormText
} from 'reactstrap';
import classnames from 'classnames/bind';
import styles from './styles.module.scss';
const cx = classnames.bind(styles);
const customComponent = props => {
const { register, handleSubmit } = useForm();
return (
<div className={styles.container}>
<div className={styles.heading}>
<span className={styles.label}>
{heading}
</span>
</div>
<form>
<Col className={'p-0'}>
<Input
className={cx(styles.customCss, 'border-0 p-0')}
id="customer"
name="customer"
defaultValue={lot}
innerRef={register}
type={'textarea'}
readOnly
/>
</Col>
</form>
</div>
);
};
export default customComponent;
【问题讨论】:
标签: reactjs reactstrap