Changing padding to a percentage

We never had to change our padding left or right to a percentage because we didn't have any, but the process to do so is very similar. You still use the same formula – target divided by context equals result. But the context is a little different now; it's the width of the element itself and not the width of the parent element, like it is for width and margin. The only caveat to that is if the element itself doesn't have a width defined, you can use the width of its parent or determine the width itself by determining the width of the parent:

If you're using the box-sizing property with the border box value, ...

Get Mastering CSS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.