CSS: I can't set width to “auto” always appear 100%

后端 未结 7 869
太阳男子
太阳男子 2021-01-28 16:56

for some reason

the width of the div is 100% and if i set it to auto, nothing changes. tried display: block; and still nothing.

what I have in

相关标签:
7条回答
  • 2021-01-28 17:23

    The following options can change the behavior of width: auto from using the available container width to so called shrink-to-fit algorithm:

    1. Float:left/right
    2. Position: absolute
    3. Display: inline-block
    4. Display: inline-table
    5. Display: table
    6. Display: table-cell

    Assuming you need that the blocks to stay in the block formatting context of the normal flow (i.e. to go one after another vertically as usually, just have the width of their content), I suppose that in this case display: table will be the best solution.

    0 讨论(0)
提交回复
热议问题