HTML-CSS: Popout menu
HTML-CSS : Exercise-23 with Solution
Using HTML, CSS reveals an interactive popout menu on hover/focus.
- Use left: 100% to move the popout menu to the right of the parent.
- Use visibility: hidden to hide the popout menu initially, allowing for transitions to be applied (unlike display: none).
- Use the :hover, :focus and :focus-within pseudo-class selectors to apply visibility: visible to the popout menu, displaying it when the parent element is hovered/focused.
HTML Code:
Explanation:
- This HTML code creates a simple webpage with a container div for a reference element and a popout menu.
- The comment indicates the license information for the code.
- <!DOCTYPE html> declares the document type and version of HTML, which is HTML5.
- <html> marks the start of the HTML document.
- <head> contains meta-information about the HTML document, such as character encoding and viewport settings.
- The <title> element sets the title of the webpage.
- <body> contains the content of the HTML document.
- Within the reference container, there's a div with the class "popout-menu" representing the popout menu.
CSS Code:
Explanation:
- .reference styles the reference container, positioning it relative to its normal position and setting its background color, width, and height.
- .popout-menu styles the popout menu, positioning it absolutely relative to its nearest positioned ancestor, hiding it by default, setting its background color, text color, and padding.
- The .reference:hover > .popout-menu, .reference:focus > .popout-menu, and .reference:focus-within > .popout-menu selectors control the visibility of the popout menu when the reference container is hovered, focused, or focused within, respectively.
Go to:
PREV : Hamburger Button.
NEXT : Sibling fade.
HTML-CSS Editor:
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.