screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; function App() { const [show, setShow] = useState(true); const [message, setMessage] = useState('This is Warning alert'); const timer = setTimeout(() => { setShow(false); }, 5000); return ( <div className='container'> <h2>React Js Hide Alert After 5 Seconds or onclick</h2> {show && ( <div className="alert alert-warning"> {message} <button onClick={() => setShow(false)} className="close-btn">×</button> </div> )} <button onClick={() => setShow(true)} className="show-alert-btn">Show Alert</button> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); width: 600px; margin: 0 auto; padding: 20px; } .alert { display: flex; align-items: center; justify-content: space-between; padding: 15px; border-radius: 5px; font-size: 16px; background-color: #fff3cd; border: 1px solid #ffeeba; color: #856404; position: relative; animation-fill-mode: forwards; } .alert-warning { background-color: #fff3cd; border-color: #ffeeba; color: #856404; } .close-btn { font-size: 22px; font-weight: bold; color: #856404; background-color: transparent; border: none; cursor: pointer; position: absolute; top: 50%; right: 10px; transform: translateY(-50%); } .close-btn:hover { color: #6A5003; } .show-alert-btn { padding: 10px 20px; font-size: 16px; background-color: #3498db; color: #fff; border: none; border-radius: 5px; margin-top: 10px; cursor: pointer; transition: background-color 0.3s ease; } /* Hover effect */ .show-alert-btn:hover { background-color: #2980b9; } </style> </body> </html>