screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.production.min.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js"></script> <script src="https://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; const App = () => { const [selectedCountry, setSelectedCountry] = useState(''); // State to track the selected country // Event handler to update the selectedCountry state when dropdown selection changes const handleDropdownChange = (event) => { const selectedValue = event.target.value; setSelectedCountry(selectedValue); }; return ( <div className='container'> <h3>React js show hide div based on dropdown selection</h3> <select onChange={handleDropdownChange}> <option value="">Select a country</option> <option value="United States">United States</option> <option value="Canada">Canada</option> <option value="United Kingdom">United Kingdom</option> {/* Add more countries as needed */} </select> {/* Div to display country information */} {selectedCountry === 'United States' && ( <div> <h3>United States</h3> <p> The United States of America is a country primarily located in North America. </p> </div> )} {selectedCountry === 'Canada' && ( <div> <h3>Canada</h3> <p> Canada is a country in the northern part of North America. </p> </div> )} {selectedCountry === 'United Kingdom' && ( <div> <h3>United Kingdom</h3> <p> The United Kingdom of Great Britain and Northern Ireland, commonly known as the United Kingdom (UK). </p> </div> )} {/* Add more div blocks for other countries as needed */} </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> /* Styles for the container and button */ .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; } /* Styling for the select element */ .container select { width: 100%; padding: 10px; margin-bottom: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; outline: none; } /* Styling for the option elements */ .container option { font-size: 16px; } button { background-color: #007bff; color: #fff; border: none; padding: 10px 20px; border-radius: 4px; cursor: pointer; font-size: 16px; transition: background-color 0.3s ease; } /* Hover effect for the button */ button:hover { background-color: #0056b3; } </style> </body> </html>