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 [imageArray, setImageArray] = useState([ "https://www.sarkarinaukriexams.com/images/import/sne4446407201.png", "https://www.sarkarinaukriexams.com/images/import/sne86811832.png", ]); const [imageUrlInput, setImageUrlInput] = useState(''); const addImage = () => { if (imageUrlInput.trim() !== '') { setImageArray([...imageArray, imageUrlInput]); setImageUrlInput(''); } }; return ( <div className='container'> <h3>React Js Add Image in array</h3> <div className="image-container"> {imageArray.map((imageUrl, index) => ( <img key={index} src={imageUrl} alt={`Image ${index}`} /> ))} </div> <div> <input type="text" placeholder="Enter Image URL" value={imageUrlInput} onChange={(e) => setImageUrlInput(e.target.value)} /> <button onClick={addImage} className="button">Add Image</button> </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); text-align: center; max-width: 600px; margin: 0 auto; } .image-container { display: flex; flex-wrap: wrap; justify-content: center; } .image-container img { width: 150px; height: 150px; object-fit: cover; margin: 10px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); } h3 { font-size: 24px; color: #333; } input { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #ccc; border-radius: 4px; outline: none; font-size: 16px; } /* Styling for the "Add Image" button */ .button { display: inline-block; padding: 10px 20px; background-color: #3498db; color: #fff; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; transition: background-color 0.3s ease; } .button:hover { background-color: #2980b9; } </style> </body> </html>