0

I have this code:

const styles = theme => ({
  root: {
    paddingTop: theme.spacing.unit * 3,
    paddingBottom: theme.spacing.unit * 3,
    paddingLeft: 0,
    paddingRight: 0,
  }
});

Is it posible to set padding with only one line? (I want to do something like this:)

const styles = theme => ({
  root: {
    padding: 0 theme.spacing.unit * 3',
  }
});
1
  • yes, you can, try padding: theme.spacing.unit*3 0, Commented Jul 17, 2018 at 16:07

1 Answer 1

1

Yes, you can do it by creating the string like so (using template literals):

const styles = theme => ({
  root: {
    padding: `${theme.spacing.unit * 3} 0`,
  }
});

If the theme spacing unit was 10px that would result in padding: 10px 0, which is shorthand for padding: 10px 0 10px 0;

It is important to use the back ticks (`) and not quotes.

One thing to note, if your theme.spacing.unit does not include the unit of measure, add it after the curly braces like so:

padding: `${theme.spacing.unit * 3}px 0`,
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I've forgot about "px"))) The last variant works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.