I decided to keep the previous answer because it demonstrates how to resolve this problem using react-jss. The same solution can be achieved with makeStyles in MaterialUI. It seems like there was a syntax error somewhere that prevented my css rules from taking effect.
Here is the code using makeStyles, with some breakpoint code included:
import { makeStyles } from '@material-ui/core/styles';
const Header = () => {
const useStyles = makeStyles(theme => ({
root: {
padding: theme.spacing(1),
[theme.breakpoints.down('sm')]: {
backgroundColor: 'red',
},
[theme.breakpoints.up('md')]: {
backgroundColor: 'blue',
},
[theme.breakpoints.up('lg')]: {
backgroundColor: 'green',
},
},
mainNav: {
zIndex: '3',
color: 'white',
textAlign: 'right',
marginRight: '10%',
'& ul': {
zIndex: '2',
textAlign: 'right',
listStyleType: 'none',
margin: '0px',
}
},
li: {
display: 'inline-block',
marginLeft: '3%',
'& a': {
color: 'white',
textDecoration: 'none',
marginRight: '10px',
padding: '10px',
'&:hover': {
background: '#3498db'
}
}
},
mainNavWrapper: {
background: 'rgba(0,0,0,1)',
width: '100%',
opacity: '1',
transition: 'width 2s ease',
padding: '10px',
position: 'fixed',
zIndex: 1,
'& .sticky': {
position: 'fixed',
top: '0px',
opacity: '1',
transition: 'opacity 2s ease',
padding: '10px',
zIndex: 1
},
'& .scrolling': {
opacity: '0',
position: 'fixed',
transition: 'opacity 30ms ease'
}
},
...
inside the functional component's return ():
<div className={classes.root}>
<div className={classes.mainNavWrapper}>
<nav className={classes.mainNav}>
<ul className={classes.ul}>
<li className={classes.li}><a href="#" >home</a></li>
<li className={classes.li}><a href="#">about us</a></li>
<li className={classes.li}><a href="#">packages</a></li>
<li className={classes.li}><a href="#">reviews</a></li>
<li className={classes.li}><a href="#" className={classes.current}>contact us</a></li>
</ul>
</nav>
</div>
</div>