CSS - Div must match content and line break

Is there a way to make a div element match its contents AND break the line so that the next element is under that div?

I tried setting the display property to inline-block , but then the div no longer breaks the line ... By default, it breaks the line, but does not match its contents.

Hope someone can help me.

Thanks!

+4
source share
2 answers

If you are trying to do this without an extra div, I don't think there is a way. Here as with two divs:

 <div> <div style="background-color: #FF0000; display: inline">Test</div> </div> 
+4
source

Something like this buddy?

http://jsfiddle.net/A6n2h/2/

I used this CSS code:

 .container div *{float:left; display:inline-block; clear:both;} 

There were also a few errors in your HTML code.

+1
source

Source: https://habr.com/ru/post/1341167/


All Articles