Min-width, max-width css use smallest width

前端 未结 3 1928
野的像风
野的像风 2021-01-05 05:26

Alright, so what I\'m hoping to do is to create a DIV that will autosize based on the content that\'s in it, but it should use the smallest width possible. I haven\'t a clue

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-05 06:23

    You can "shrink-wrap" a div in a few different ways. The easiest is probably to display: inline; but a float will behave like you describe as well.

    Check out http://haslayout.net/css-tuts/CSS-Shrink-Wrap for details and more methods.

    If you want the minimum width to be 200px (contradictory to your first paragraph) you can use min-width: 200px; along with display: inline-block for instance.

提交回复
热议问题