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 [isButtonActive, setIsButtonActive] = useState(false); return ( <div className='container'> <h3>React Js Change Button Color onclick| Background Color</h3> <button className={`my-button ${isButtonActive ? 'active-button' : ''}`} onClick={() => setIsButtonActive(!isButtonActive)} > Toggle Button Background Color </button> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Style the container */ .container { max-width: 600px; margin: 0 auto; padding: 20px; text-align: center; border-radius: 10px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); } /* Styling for the button */ .my-button { padding: 10px 20px; font-size: 16px; background-color: #3498db; color: #fff; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s; } .my-button:hover { background-color: #2980b9; } /* Styling for the active button state */ .active-button { background-color: #e74c3c; } .active-button:hover { background-color: #c0392b; } </style> </body> </html>