So I am having this strange issue where i have an element in a container and it is inheriting the width from the conatiner.
to try and fix this i just set the css width property to whatever i want. when i go to preview in the browser it has adjusted the width properly, but it has now extended out the right margin to fill in the container.
I tried to offset this by doing things like margin-right: 0; or using negative values, but nothing is working
The width of the child is never inherited from the parent(the exact value specified on the parent)! However, it is dependent on the parent’s width. If you specify a width on the parent and have a block-level child, it will always expand to 100% of the parents width. That is completely normal behavior.
If you set an explicit width on a child-element, you have to be aware, that it’s padding and border are not accounted into the total width (using standard box modell). You have two options:
the css:
note however, that
box-sizingis a newer css-property and not every browser can handle it.