screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <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 type="text/babel"> const { useState } = React; function App() { // State to store the image URL const [imageUrl, setImageUrl] = useState('https://www.sarkarinaukriexams.com/images/bio/1695902312-bio.png'); // Function to handle user input or API response to change the image URL const handleInputChange = (event) => { setImageUrl(event.target.value); }; return ( <div className='container'> <h3>React Js Display Image using useState</h3> {/* Input field to allow users to enter the image URL */} <input type="text" placeholder="Enter Image URL" value={imageUrl} onChange={handleInputChange} className="input-field" // Add a class name to the input field /> {/* Display the image using the updated imageURL state */} <img src={imageUrl} alt="Image Description" className="image-element" /> {/* Add a class name to the image */} </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style scoped> .container { max-width: 600px; margin: 0 auto; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.2); } /* Input field styles */ .input-field { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; margin-bottom: 20px; font-size: 16px; outline: none; box-sizing: border-box; } .input-field::placeholder { color: #aaa; /* Placeholder text color */ } /* Image styles */ .image-element { max-width: 100%; height: auto; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); /* Box shadow for the image */ border-radius: 5px; } /* Optional: Add hover effect to the image */ .image-element:hover { transform: scale(1.05); /* Increase size on hover */ transition: transform 0.3s ease; } </style> </body> </html>