How can I adjust DIV width to contents

前端 未结 5 1662
一向
一向 2021-01-31 14:59

I have a div element with style attached:

.mypost {
    border: 1px solid Peru;
    font-family: arial;
    margin: auto;
    min-width: 700px;
    width: 700px;         


        
5条回答
  •  别跟我提以往
    2021-01-31 15:06

    You could try using float:left; or display:inline-block;.

    Both of these will change the element's behaviour from defaulting to 100% width to defaulting to the natural width of its contents.

    However, note that they'll also both have an impact on the layout of the surrounding elements as well. I would suggest that inline-block will have less of an impact though, so probably best to try that first.

提交回复
热议问题