我有一个对象,其中包含我所需要的模态框样式:
const customStyles = {
content: {
top: '35%',
left: '50%',
right: 'auto',
bottom: 'auto',
marginRight: '-50%',
width: '60%',
transform: 'translate(-40%, -10%)',
},
};
然后我将这些样式传递给模态框,像这样:
<Modal
isOpen={this.state.modalIsOpen}
onRequestClose={this.closeModal}
style={customStyles}
>
这段代码可以正常工作,但是我想传递一个类,而不是在组件内创建一个自定义样式对象。
我尝试了以下代码,首先创建模态框类:
.modal {
top: '35%';
left: '50%';
right: 'auto';
bottom: 'auto';
marginRight: '-50%';
width: '60%';
transform: 'translate(-40%, -10%)';
}
然后:
<Modal
isOpen={this.state.modalIsOpen}
onRequestClose={this.closeModal}
className="modal"
>
但是它没有起作用。我做错了什么吗?