How to make a parent div auto size to the width of its children divs

前端 未结 2 1361
失恋的感觉
失恋的感觉 2021-02-01 11:47

I\'m trying to make the parent div only as wide as the child div\'s. Auto width is making the parent div fit the entire screen. The children divs will be different widths depend

相关标签:
2条回答
  • 2021-02-01 12:14

    The parent div (I assume the outermost div) is display: block and will fill up all available area of its container (in this case, the body) that it can. Use a different display type -- inline-block is probably what you are going for:

    http://jsfiddle.net/a78xy/

    0 讨论(0)
  • 2021-02-01 12:21

    Your interior <div> elements should likely both be float:left. Divs size to 100% the size of their container width automatically. Try using display:inline-block instead of width:auto on the container div. Or possibly float:left the container and also apply overflow:auto. Depends on what you're after exactly.

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