C # - How can I cut a line at the end to fit in a div?

I am making a list of breaking news. So, it will show something like this:

- Take a look at the new Volks...
- John Doe is looking for a jo...
- Microsoft is launching the n...

So, in the above list only the headline of the news is shown, and the length of each news is limited to 25 characters. But this doesn’t work well ... for example, if you type 25 M, it will blow my div.

I was told that there is a way to calculate the length of a string and make it fit in the div automatically.

Does anyone know how to do this?

thanks!!

+3
source share
7 answers

I think you are talking about using the System.Drawing.Gaphicsclass method MeasureString().

Graphics, -. -, CSS.

+1

"text-overflow: ellipsis" - , , . ...

+3

, css .

word-wrap:break-word;

+1

" div" - css, overflow div, , .

+1

, , . - , , - 25 * .

, , , X. css .

0

, , . Ajax - , ( ) . , , .

:

  • span. . jQuery javascript, , . ( , )
  • . div overflow:hidden div. , , .
  • - ( ).
0

, System.Drawing.Graphics.MeasureString, , , div HTML, CSS.

<html>
<head>
    <title>C# - How can I cut a string at its end to fit in a div? </title>
    <style type="text/css">
        .ellipsis li
        {
           display: block; 
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            width: 166px;
        }
    </style>
</head>
<body>
    <ul class="ellipsis">
        <li>Take a look at the new Volksxxxxx</li>
        <li>John Doe is looking for a joxxxxx</li>
        <li>Microsoft is launching the nxxxxx</li>
    </ul>
</body>
</html>

(UL) div, . CSS DIV. , text-overflow: .

0

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


All Articles