search

Home  >  Q&A  >  body text

How to truncate getting anchor tag text in HTML table

<p>I'm trying to truncate text within the anchor text of an element. I added <code>overflow: hidden; text-overflow: ellipsis;</code> in the style of my anchor tag, but it still wraps.这里有一些可以复现的HTML:</p> <p><br /></p> <pre class="brush:html;toolbar:false;"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Test Test 123</title> </head> <body> <div style="width: 100%; padding-top: 1px;"> <div class="contents" style="width: 512px; flex-shrink: 0; margin-left: auto; margin-right: auto; display: block;"> <div class="contents-body" style="display: block; width: 512px;"> <table style="width:50%; border-collapse: collapse; margin-left: auto; margin-right: auto;"> <tbody> <tr style="justify-content:center;align-items:center;gap:56px;color:#848585"> <th style="padding-top:8px;padding-bottom: 10px; font-style:normal;font-weight:500;line-height:16px;letter-spacing:0.1px;text-align:left;width:25%">Column A</th> <th style="padding-top:8px;padding-bottom: 10px; font-style:normal;font-weight:500;line-height:16px;letter-spacing:0.1px;text-align:left;width:25%">Column B</th> </tr> <tr> <td rowspan="3" style="width:25%; padding-top:8px; padding-bottom:8px; text-align:left;font-size:14px;font-style:normal;font-weight:500;line-height:16px; letter-spacing:0.1px;">Entry A</td> <td style="padding-top:8px; padding-bottom:8px; text-align:left;font-size:14px;font-style: normal;font-weight:400;line-height: 16px;letter-spacing:0.1px;text-decoration-line:underline;"> <a style="color:#E25323; overflow: hidden; text-overflow: ellipsis; width: 50 px;" href="https://localhost">ABC123ABC-ABC123ABC`</a> </td> </tr> </tbody> </table> </div> </div> </div> </body> </html></pre> <p><br /></p> <p> It doesn't seem to like the 50px width on the anchor tag text, I think it's the column width that's messing with it. </p>
P粉547170972P粉547170972500 days ago521

reply all(1)I'll reply

  • P粉099145710

    P粉0991457102023-08-17 00:29:51

    If you don’t want to wrap, you can add white-space:nowrap;
    If you want to set width, set it to 50px instead of 50 px (no spaces allowed);
    If you want width to take effect, set your <a> to a block-level element, e.g. using display:inline-block

    Here is the code:

    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
      <title>Test Test 123</title>
    </head>
    
    <body>
      <div style="width: 100%; padding-top: 1px;">
        <div class="contents" style="width: 512px; flex-shrink: 0; margin-left: auto; margin-right: auto; display: block;">
          <div class="contents-body" style="display: block; width: 512px;">
            <table style="width:50%; border-collapse: collapse; margin-left: auto; margin-right: auto;">
              <tbody>
                <tr style="justify-content:center;align-items:center;gap:56px;color:#848585">
                  <th style="padding-top:8px;padding-bottom: 10px; font-style:normal;font-weight:500;line-height:16px;letter-spacing:0.1px;text-align:left;width:25%">Column A</th>
                  <th style="padding-top:8px;padding-bottom: 10px; font-style:normal;font-weight:500;line-height:16px;letter-spacing:0.1px;text-align:left;width:25%">Column B</th>
                </tr>
                <tr>
                  <td rowspan="3" style="width:25%; padding-top:8px; padding-bottom:8px; text-align:left;font-size:14px;font-style:normal;font-weight:500;line-height:16px; letter-spacing:0.1px;">Entry A</td>
                  <td style="padding-top:8px; padding-bottom:8px; text-align:left;font-size:14px;font-style: normal;font-weight:400;line-height: 16px;letter-spacing:0.1px;text-decoration-line:underline;">
                    <a style="color:#E25323; overflow: hidden; text-overflow: ellipsis; display:inline-block; width: 50px; white-space:nowrap" href="https://localhost">ABC123ABC-ABC123ABC`</a>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </body>
    
    </html>

    reply
    0
  • Cancelreply