Created
January 15, 2020 23:34
-
-
Save wutangpaul/9aa1aac0886605d5768be480abf5a8c4 to your computer and use it in GitHub Desktop.
styled components child hover
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import styled from "styled-components"; | |
const NavBar = styled.div` | |
background-color: cornflowerblue; | |
padding: 1rem; | |
`; | |
const FlyoutMenu = styled.div` | |
background-color: limegreen; | |
visibility: hidden; | |
`; | |
const NavBarMenuItem = styled.div` | |
background-color: #f09; | |
&:hover ${FlyoutMenu} { | |
visibility: visible; | |
} | |
`; | |
const NavBarMenuItemLink = props => { | |
return <a href={props.to}>{props.title}</a>; | |
}; | |
const FlyoutMenuItem = props => { | |
return <a href={props.to}>{props.title}</a>; | |
}; | |
function App() { | |
return ( | |
<> | |
<NavBar> | |
<NavBarMenuItem> | |
<NavBarMenuItemLink | |
to="/foo" | |
title="Menu item 1" | |
></NavBarMenuItemLink> | |
<FlyoutMenu> | |
<FlyoutMenuItem to="/bar" title="Sub menu item 1"></FlyoutMenuItem> | |
<FlyoutMenuItem to="/bar" title="Sub menu item 2"></FlyoutMenuItem> | |
<FlyoutMenuItem to="/bar" title="Sub menu item 3"></FlyoutMenuItem> | |
<FlyoutMenuItem to="/bar" title="Sub menu item 4"></FlyoutMenuItem> | |
</FlyoutMenu> | |
</NavBarMenuItem> | |
</NavBar> | |
</> | |
); | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment