How does the CSS "Shrinkwrap" method work with max-width and without the BR interrupt tag?

I am trying to create a max-width bounding box that will both wrap the text (by spaces or word resolution) and reduce the width of the longest line of text. For a demonstration of various shrink methods, see http://www.brunildo.org/test/IEMshrink-to-fit.html

I chose the "float" method, but in my testing none of the methods achieved the desired effect.

In the code example below (also available with live-preview in jsbin ), I show what happens when you release the words to wrap yourself and what happens when you insert a line break tag <br /> . Using <br /> manually leads to the exact result that I am looking for, while omitting it, it wraps the text correctly, but forces the white box to use the entire maximum width as its width, which I would like to avoid.

 <style> div#wrapper { background: #ddd; padding: 10px; } header { display: block; float: left; max-width: 320px; background: #fff; margin-bottom: 20px; clear: both; } #wrapper:after { content: " "; clear: both; display: table; } </style> <div id="wrapper"> <header> <h1>Diane Von Furstenberg</h1> </header> <header> <h1>Diane Von<br />Furstenberg</h1> </header> </div> 

Here is a screenshot of the problem with some detail:

Screenshot of Shrinkwrap CSS issue

I created a JS method for manually inserting a <br /> tag as a stop measure, but I suppose there should be some way to do it right using only CSS / HTML. Thanks for the help!

+4
source share
2 answers

Changing the display of the h1 header in the table is getting closer to what you want in Google Chrome. But this is not ideal, and I can not really recommend this as a solution completely, mainly because I did not test it in any other browsers.

+1
source

Not sure if the browser behavior has changed since the "table-caption" response was sent, but it currently does not work (using Chromium 41):

enter image description here

In fact, it seems that the desired behavior is not possible with pure CSS (as of 2015). Further explanation and a lightweight Javascript workaround are available in another SO question: is max-width suitable for text?

0
source

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


All Articles