Reputation: 175
In this page, when .gridster > ul
's width is changed, but .gridster
's width stays. Normally, parent element's width changes as the child element's width changes. Why it stays the same in this case. How to make the parent element's width is equal to the child element's all the time.
Upvotes: 0
Views: 414
Reputation: 288020
Because .gridster
is a block-level non-replaced element.
10.3 Calculating widths and margins
10.3.3 Block-level, non-replaced elements in normal flowThe following constraints must hold among the used values of the other properties:
'margin-left' + 'border-left-width' + 'padding-left' + 'width' + 'padding-right' + 'border-right-width' + 'margin-right' = width of containing block
If 'width' is set to 'auto', any other 'auto' values become '0' and 'width' follows from the resulting equality.
In this case,
width
is not set, so its value is the initial auto
.auto
.border-*-style
are not set, so their value is the initial none
. Thus the horizontal border-*-width
compute to 0
.0
.Then,
0
.0
because the width
is auto
.width
computes to the width of the containing block.Upvotes: 3