I'm trying to style a modal in ReactJS and would like some help. I'm facing difficulty in trying to center align the content modal. In addition, when styling the modal, is it possible to assign a className and style it in the css page? I've tried doing that but it doesn't work. So I just decided to do inline styling but I can't center align my modal.
<button onClick={()=> SEOsetModalIsOpen(true)} className="viewmore">
View More
<ArrowIcon className="arrowright"/>
</button>
<Modal
isOpen={SEOmodalIsOpen}
shouldCloseOnOverlayClick={true}
onRequestClose={()=>SEOsetModalIsOpen(false)}
style={{
overlay: {
position: 'fixed',
top: 0,
left: 0,
right: 0,
bottom: 0,
opacity: 1,
},
content: {
position: 'absolute',
width: '500px',
height: '300px',
top: '200px',
left: '500px',
right: '500px',
bottom: '200px',
border: '1px solid #ccc',
background: 'blue',
overflow: 'auto',
WebkitOverflowScrolling: 'touch',
borderRadius: '4px',
outline: 'none',
padding: '20px'
}
}}
>
<h2>Search Engine Optimisation</h2>
<p>Hello World</p>
<button onClick={()=>SEOsetModalIsOpen(false)}>Close</button>
</Modal>
</div>
You could use this to center it with absolute positioning:
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);