【发布时间】:2018-09-16 22:35:35
【问题描述】:
我有这个对象,带有我想要的模态样式:
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}
>
它工作正常,但我想传递一个类,而不是在组件内创建 customStyle 对象。
我尝试这样的事情,首先创建模态类:
.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"
>
但它没有用。我做错了什么?
【问题讨论】:
-
在我看来,您似乎没有做错什么。有可能你没有包含你的 CSS 或者你已经加载了一些覆盖你的 CSS 所做的事情。尝试更改您申请的课程的名称,看看是否有效。否则,请使用控制台检查器查看是否有任何内容优先于您的 CSS,或者是否已加载。
标签: javascript css reactjs modal-dialog styles