【发布时间】:2020-01-20 23:13:06
【问题描述】:
我正在使用带有 Bootstrap 和样式 JSX 的 Next.js (React)。我遇到了一个问题,即 Bootstrap 中用于模态的自定义类仅在 css 为全局时才使用 css 样式。我使用 Modal 上的 dialogClassName 属性声明自定义类。这是我的函数组件(我正在使用 Typescript):
const Form: React.FunctionComponent<props> = (props: props) => {
const [FormVisibility, FormDispatch] = useContext(FormContext);
return (
<Modal
show={props.isVisible}
onHide={() => {FormDispatch({ type: ActionTypes.CloseForm }) }}
backdrop="static"
dialogClassName="custom-modal"
>
<Modal.Header closeButton >
<Modal.Title>Modal heading</Modal.Title>
</Modal.Header>
<Modal.Body>Woohoo, you're reading this text in a modal!</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={() => {FormDispatch({ type: ActionTypes.CloseForm }) }}>
Close
</Button>
</Modal.Footer>
<style jsx global>{`
.custom-modal {
color: blue;
height: 75vh;
width: 75vw;
max-width: none !important;
}
`}
</style>
</Modal>
);
}
这很好用。但是如果我将<style jsx global> 更改为<style jsx>,则不会应用样式。我在这里做错了什么还是有更好的方法来做到这一点?对我来说似乎很奇怪,即使组件在本地声明了类,也需要 global。
谢谢!
【问题讨论】:
标签: css reactjs twitter-bootstrap jsx next.js