Why does padding changes width




















How do I prevent the padding property from changing width or height in CSS? Ask Question. Asked 12 years, 6 months ago. Active 3 years, 5 months ago. Viewed k times.

How can I fix this problem? Sam Sam I'm sad to say, but I like how IE handles this Makes much more sense to me Add a comment. Active Oldest Votes. Abhishek Pandey Pramod Pramod 4, 1 1 gold badge 11 11 silver badges 2 2 bronze badges. This is a great solution for borders, but how does this help for padding?

This is pure magic! Whoops yeah, copy and paste cock up. This is the link I meant to share Let's say I create another DIV named anotherdiv exactly the same as newdiv, and put it inside of newdiv but newdiv has no padding and anotherdiv has padding-left: 20px. I get the same thing, newdiv's width will be px;. How do I prevent the padding property from changing width or height in CSS?

How can I fix this problem? Asked By: Sam. Adjoining margins can be generated by elements that are not related as siblings or ancestors. Note the above rules imply that: Margins between a floated box and any other box do not collapse not even between a float and its in-flow children.

Margins of elements that establish new block formatting contexts such as floats and elements with 'overflow' other than 'visible' do not collapse with their in-flow children.

Margins of absolutely positioned boxes do not collapse not even with their in-flow children. Margins of inline-block boxes do not collapse not even with their in-flow children. The bottom margin of an in-flow block-level element always collapses with the top margin of its next in-flow block-level sibling, unless that sibling has clearance. The top margin of an in-flow block element collapses with its first in-flow block-level child's top margin if the element has no top border, no top padding, and the child has no clearance.

The bottom margin of an in-flow block box with a 'height' of 'auto' and a 'min-height' of zero collapses with its last in-flow block-level child's bottom margin if the box has no bottom padding and no bottom border and the child's bottom margin does not collapse with a top margin that has clearance.

A box's own margins collapse if the 'min-height' property is zero, and it has neither top or bottom borders nor top or bottom padding, and it has a 'height' of either 0 or 'auto', and it does not contain a line box, and all of its in-flow children's margins if any collapse.

When two or more margins collapse, the resulting margin width is the maximum of the collapsing margins' widths. In the case of negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum of the positive adjoining margins.

If there are no positive margins, the maximum of the absolute values of the adjoining margins is deducted from zero. If the top and bottom margins of a box are adjoining, then it is possible for margins to collapse through it.

In this case, the position of the element depends on its relationship with the other elements whose margins are being collapsed. If the element's margins are collapsed with its parent's top margin, the top border edge of the box is defined to be the same as the parent's.

Otherwise, either the element's parent is not taking part in the margin collapsing, or only the parent's bottom margin is involved. The position of the element's top border edge is the same as it would have been if the element had a non-zero bottom border. Note that the positions of elements that have been collapsed through have no effect on the positions of the other elements with whose margins they are being collapsed; the top border edge position is only required for laying out descendants of these elements.

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations. Treehouse offers a seven day free trial for new students.

Get access to thousands of hours of content and a supportive community.



0コメント

  • 1000 / 1000