skip to Main Content

Can I use the CSS calc function to subtract a percentage from a percentage? Example: margin-left:calc(100% – 14%);

This is what I tried calc(100% – (6 * 12%)). I have 6 boxes with with being 12% of the container they are in.

2

Answers


  1. example paste this in your html page

    <style>
    margin-right: calc((100% - (6 * 12%)) / 5);
    </style>
    

    you can tweak your calculation according to the above example.

    Login or Signup to reply.
  2. Yes, you can absolutely use the cal() function in css to subtract percentage from percentages.your example is valid.
    For your specific case with 6 boxes each being 12% of the container width, if you want to subtract 12% six times from 100%, you can do it like this:
    margin-left: calc(100% – (6 * 12%));

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search