Maximum length of Div and Span elements

How to set maximum length for Span and Div elements?

+3
source share
4 answers

there is

max-height / max-width

CSS properties that limit the width of block-level elements (i.e. not spans). Link

Please note that they are not supported by IE 6 .

+4
source

When the contained word is too large, the div or span may overflow:

<div style="width: 80px; overflow: hidden;" >hhhhhhheeeeeellllllllllooooo</div>
  • You can wrap span with div. It will shorten the content if there are no spaces in the text, but this will prevent overflow.

If long words are problems, a CSS3 solution might be:

style = "width: 80; word-wrap: break-word;"

+1

mesn, css:

<div style='max-width:100px'>Content</div>
<span style='max-width:100px; display:block;'>Content</span>

If you really mean the length of the content, you cannot in HTML. For this you need to use a javascript piece. Take a look at jQuery, it is very easy to do. It will come down to something like:

$('#yourDivId').html().length
0
source

Do you mean maximum width?

max-width: ??px;
0
source

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


All Articles