Skip to content

Instantly share code, notes, and snippets.

@wutangpaul
Created January 15, 2020 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wutangpaul/9aa1aac0886605d5768be480abf5a8c4 to your computer and use it in GitHub Desktop.
Save wutangpaul/9aa1aac0886605d5768be480abf5a8c4 to your computer and use it in GitHub Desktop.
styled components child hover
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