If I distort a container with the skew property, then the short corners are inside the original dimensions and the long corners are outside. This can be seen in diagram 1 with the blue box.
diagram 1 : 
However, I would like the outer corners not to exceed the original width, as in diagram 2 with the red box.
diagram 2 : 
I could basically solve this with margin, but the protruding width depends on the length of the container.
Is there a way not to exceed the original width?
I have tried to work with margin, but since the height of the box is not known, I cannot calculate the margin
Pure CSS
If the height and width of the container
divare known, you could try something like this, utilising the formula 'a = b x tan(α)' for finding the additional length after the skew and subtracting it from the overall width of thediv.This source can better explain the math if you're unfamiliar with it.
You can adjust the width variable in the code snippet to see it work.
JavaScript
If the height and width values of the container are not known, you can retrieve them using JavaScript and use the same calculation to set the width of the child element.
Be aware that Math.tan() uses radians instead of degrees so a conversion is required if you're also using degrees.