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; function Accordion({ title, content }) { const [isOpen, setIsOpen] = useState(false); const toggleAccordion = () => { setIsOpen(!isOpen); }; return ( <div className={`accordion ${isOpen ? 'open' : ''}`}> <div className="accordion-header" onClick={toggleAccordion}> <h3>{title}</h3> <span className={`icon ${isOpen ? 'open' : ''}`}>{isOpen ? '-' : '+'}</span> </div> {isOpen && <div className="accordion-content">{content}</div>} </div> ); } function App() { return ( <div className="App"> <h3>React Js Collapsible Accordion</h3> <Accordion title="Home" content="A home button on a website is a clickable element, often represented as a house icon, that returns users to the website's main or starting page." /> <Accordion title="About" content="A website button is a clickable element that triggers actions like navigation, submitting forms, or initiating interactions, enhancing user experience and site functionality." /> <Accordion title="Contact Me" content= "A Contact Me button is a clickable element on a website or app that allows users to initiate communication with the owner or representative for inquiries, feedback, or assistance." /> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> body { margin: 0; font-size: 16px; font-family: Arial, Helvetica, sans-serif; display: flex; justify-content: center; align-items: center; } .App { display: flex; flex-direction: column; align-items: center; } .accordion { width: 400px; background-color: #fff; border: 1px solid #ccc; margin: 10px; border-radius: 5px; overflow: hidden; transition: height 0.3s ease-in-out; } .accordion-header { display: flex; justify-content: space-between; align-items: center; padding: 0px 20px; cursor: pointer; background-color: #f1f1f1; transition: background-color 0.3s ease-in-out; } .accordion-header:hover { background-color: #e0e0e0; } .accordion-content { padding: 10px 20px; max-height: 0; overflow: hidden; transition: max-height 0.3s ease-in-out; } .accordion.open .accordion-content { max-height: 200px; /* Set a maximum height for content */ } .icon { font-size: 24px; transition: transform 0.3s ease-in-out; display: inline-block; /* Ensure the icon doesn't affect layout */ } .icon.open { transform: rotate(180deg); } </style> </body> </html>