【发布时间】:2016-07-28 16:58:37
【问题描述】:
我正在使用 dialogClassName 属性将 Modal 的宽度更改为 90%。 CSS 不会改变任何东西。我已经验证 style.css 适用于所有其他类。
这个 SO question 的解决方案不起作用。 documentation 也不起作用。
感谢您的帮助!
modal.js的渲染方法:
render(){
return (
<div>
<CardMain openModal={this.handleOpen}
{...this.props} />
<Modal show={this.state.open}
onHide={this.handleClose}
dialogClassName="main-modal">
<ModalMain tabKey={this.state.tabKey}
{...this.props} />
<FeedbackForm />
</Modal>
</div>
);
}
style.css:
.main-modal {
width: 90%;
}
【问题讨论】:
-
你检查过元素并检查为什么它没有被应用吗?可能你有其他 CSS 规则比这个更优先..
-
感谢您的建议。事实证明,该标签的类是“main-modal modal-dialog”。所以“模态对话框”必须覆盖它。那是内置的 react-bootstrap 模态类。知道如何覆盖它吗?
-
您可以编写内联 CSS 样式。它比引导规则具有更高的优先级。否则您可以使用模态的 ID 在您的 site.CSS 中指定规则。CSS 规则与ID 选择器具有更高的优先级。或者您可以添加一个自定义类并使用所有可能的类选择器编写您的 CSS 规则。 When the number of classes used in selectors are high it gets more priority... Use the one which suits the best for you
-
我测试了这些解决方案: 内联 CSS:我写了一个 modalStyle css 对象并设置了 dialogClassName={modalStyle}。这并没有改变什么。 id:
不起作用,因为 dialogClassName 正在为某些隐藏的对话框标签设置一个类,而不是 Modal 本身。许多类选择器:我在 .main-modal 中添加了 8 个其他类选择器,但这并没有改变任何东西。我执行您的建议有误吗? -
内联 CSS 意味着设置你元素的样式属性...就像这样
stlye=width:90%;
标签: css reactjs react-bootstrap