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 [show, setShow] = useState(false); const showOverlay = () => { setShow(true); }; const hideOverlay = () => { setShow(false); }; return ( <div id="app"> <div className="container"> <h2>React Js Display text on hover over Image</h2> <div className="image-container" onMouseOver={showOverlay} onMouseLeave={hideOverlay} > <img src="https://www.sarkarinaukriexams.com/images/editor/1684236637tree-g37135fa70_640.jpg" alt="Image" /> {show && ( <div className="overlay"> <h2>React Js Display text on hover over Image</h2> <p>Description</p> </div> )} </div> </div> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); width: 600px; margin: 0 auto; } .image-container { position: relative; display: inline-block; } .image-container img { max-width: 100%; height: auto; display: block; } .overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); color: #fff; opacity: 0; transition: opacity 0.3s ease; display: flex; flex-direction: column; justify-content: center; align-items: center; } .overlay:hover { opacity: 1; } .overlay h2 { font-size: 24px; margin-bottom: 10px; } .overlay p { font-size: 16px; } </style> </body> </html>