Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Media queries in styled-component declared with object

I write styled components like in react-native, as a js object:

const SectionTitle = styled.div({
  fontSize: '25px',
  display: 'flex',
})

Is it possible to use media queries with the above object style?

like image 224
Fellow Stranger Avatar asked Nov 23 '18 08:11

Fellow Stranger


1 Answers

Yes, this is possible. You just need to wrap your object keys with quotes to form a string from a media query rule.

For example:

const SectionTitle = styled.div({
  fontSize: '25px',
  display: 'flex',
  '@media(min-width: 788px)': {
    fontSize: '40px'
  }
})
like image 179
falinsky Avatar answered Sep 22 '22 07:09

falinsky