screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/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; const IconWithText = () => { const [isHovered, setIsHovered] = useState(false); const handleMouseEnter = () => { setIsHovered(true); }; const handleMouseLeave = () => { setIsHovered(false); }; return ( <div className="icon-container" onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} > <span className="icon">🚀</span> {isHovered && <span className="text">Launch</span>} </div> ); }; const App = () => { return ( <div className="container"> <h3>React Js Display Text when hover over Icon</h3> <IconWithText /> </div> ); }; ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { max-width: 500px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); text-align: center; } .icon-container { position: relative; display: inline-block; } .text { position: absolute; top: 100%; left: 50%; transform: translateX(-50%); background-color: rgba(0, 0, 0, 0.8); color: white; padding: 4px 8px; border-radius: 4px; white-space: nowrap; font-size: 14px; visibility: visible; opacity: 1; transition: opacity 0.2s; } .icon-container:hover .text { opacity: 1; visibility: visible; } .icon{ cursor: pointer; } </style> </body> </html>