Lets say we have a parent div of maximum width of document, and we have a child div with also maximum width, so child covered the parent div. Now if we put padding-right: 50px and padding-left 50px for example why does it push the child div from inside meaning it decreases its width?
parent div is color red and child is color blue, parent div is 100% width of document.
Padding adds a margin around the inside of an HTML element where content cannot go. (Margin, on the other hand adds a margin around the outside of the element). Within that padding margin, you’ll see the outer element - you’ll only see inner element content inside the non-padded area. You normally add padding to stop text pushing up against the wall of its outer element, in this case the blue div is being stopped from pushing up against the red wall.
The inner width is still 100%, just 100% of the outer element minus any padding.