suchen

Heim  >  Fragen und Antworten  >  Hauptteil

So kürzen Sie das Abrufen von Anker-Tag-Text in einer HTML-Tabelle

<p>Ich versuche, Text im Ankertext eines Elements abzuschneiden. Ich habe <code>overflow: versteckt; text-overflow: ellipsis;</code> im Stil meines Anker-Tags hinzugefügt, aber es wird immer noch umbrochen.这里有一些可以复现的HTML:</p> <p><br /></p> <pre class="brush:html;toolbar:false;"> <html lang="de" xmlns="http://www.w3.org/1999/xhtml"> <Kopf> <title>Test Test 123</title> </head> <Körper> <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%">Spalte 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%">Spalte 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; Buchstabenabstand: 0,1 Pixel;">Eintrag 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- Abstand:0.1px;text-decoration-line:underline;"> <a style="color:#E25323; overflow: versteckt; 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> Die 50-Pixel-Breite im Anker-Tag-Text scheint mir nicht zu gefallen, ich denke, es ist die Spaltenbreite, die das Problem stört. </p>
P粉547170972P粉547170972546 Tage vor553

Antworte allen(1)Ich werde antworten

  • P粉099145710

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

    如果你不想换行,可以添加 white-space:nowrap
    如果你想设置 width,设置为 50px,而不是 50 px(不允许有空格);
    如果你想让 width 生效,将你的 <a> 设置为块级元素,例如使用 display:inline-block

    这里是代码:

    <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>

    Antwort
    0
  • StornierenAntwort