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 [isButtonClicked, setIsButtonClicked] = useState(false); const handleButtonClick = () => { setIsButtonClicked(!isButtonClicked); }; return ( <div className='container'> <h3>React Js Change CSS on Button Click Example</h3> <button id='clickButton' onClick={handleButtonClick}> Click me to change CSS </button> <div id='content' className={isButtonClicked ? 'clicked' : ''}> <p>Click on the button to see changes in CSS</p> <span id='status'>{isButtonClicked ? 'Button Clicked' : 'Button Not Clicked'}</span> </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { max-width: 500px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; align-items: center; justify-content: center; } button#clickButton { padding: 10px 20px; font-size: 16px; background-color: #3498db; color: white; border: none; cursor: pointer; transition: background-color 0.3s ease; } button#clickButton:hover { background-color: #2980b9; } div#content { margin-top: 20px; padding: 10px; background-color: #ecf0f1; border: 1px solid #bdc3c7; border-radius: 5px; transition: background-color 0.3s ease; } div#content.clicked { background-color: #2ecc71; } p { font-size: 18px; margin: 0; } span#status { font-size: 16px; font-weight: bold; } div#content.clicked #status { color: #fff; } </style> </body> </html>