Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS' calc() in styled-components [duplicate]

Trying this:

const styledDiv = styled.div`
  ${props => props.takeViewportHeight && `min-height: calc(100vh-16px);`}
`

It's not working. Am I missing something about calc in styled components?

like image 693
R. Kohlisch Avatar asked Mar 09 '20 13:03

R. Kohlisch


People also ask

How do you reuse styled-components?

To achieve that you can simply pass the styled-component you wish to extend (or inherit styles from) to the styled() constructor, for example, like so: import styled from 'styled-components'; const Square = styled.

Can I use CSS with styled-components?

Utilising tagged template literals (a recent addition to JavaScript) and the power of CSS, styled-components allows you to write actual CSS code to style your components.

Is styled-components deprecated?

As of styled-components v4 the withComponent API is now a candidate for deprecation. In all likelihood, you probably want to use the new "as" prop to simply switch what element/component being rendered since the withComponent API is destructive toward styles if the lowest-wrapped component is a StyledComponent.

What is Calc method in CSS?

calc() The calc() CSS function lets you perform calculations when specifying CSS property values. It can be used anywhere a <length> , <frequency> , <angle> , <time> , <percentage> , <number> , or <integer> is allowed.


1 Answers

A funny tip about CSS calc:

whitespaces are required between +/-

meaning:

const styledDiv = styled.div`
  ${props => props.takeViewportHeight && `min-height: calc(100vh - 16px);`}
`

should work

like image 147
StackedQ Avatar answered Oct 09 '22 01:10

StackedQ