The margin
and width
properties are not inherited (except via the use of the inherit
value). However, an inner element appears by default within the outer element visually, so it may look like it inherited those properties. In reality, e.g. margin-left
is 0 (by default), but this means that the element starts at the same horizontal position as its parent. Similarly, width
is auto
for block elements that have no width set on them, and this means the available horizontal space.
The fix to your problem depends on what the problem is. There is no inheritance problem for these properties. But if you wish to make e.g. a child of a centered element start at the very left of the browser window, you need to e.g. set negative margin on it or to use absolute positioning.
For many other properties, such as color
, an element inherits the property from its parent if the property is not set on the element itself. If inheritance is not desirable, set the property on the inner element. There is no trick; this is how CSS works.