简体   繁体   English

文本对齐:证明在表格 td 中不起作用

[英]Text-align: justify not working in table td

I would like some text to be justified.我想要一些文字是合理的。

I tried to put text-align: justify in the td, but it doesn't work.我试图将 text-align: justify 放在 td 中,但它不起作用。 It always shows like text-align: left它总是显示为 text-align: left

HTML: HTML:

<div class="pha-wrapperTAB">
  <table class="pha-contentTAB">
    <tbody>
      <tr>
        <td>농     정     과</td>
        <td>063-454-2830</td>
      </tr>
      <tr>
        <td>농 촌 지   원 과</td>
        <td>063-454-5225</td>
      </tr>
      <tr>
        <td>기  술 보  급 과</td>
        <td>063-454-5302</td>
      </tr>
      <tr>
        <td>농산 물 유  통과</td>
        <td>063-454-3013</td>
      </tr>
      <tr>
        <td>농기계임대사업소</td>
        <td>063-454-5248</td>
      </tr>
      <tr>
        <td>농산 물가 공센터</td>
        <td>063-454-5257</td>
      </tr>
    </tbody>
  </table>
</div>

CSS: CSS:

.pha-contentTAB tr td {
  white-space: nowrap;
}
.pha-contentTAB tr td:nth-child(1) {

}
.pha-contentTAB{
  width:100%;
}
.pha-contentTAB tr td:first-child{
  width:55%;
  text-align: justify;
}
.pha-contentTAB tr td:last-child{
  font-weight:bold;
  font-size:15px;
  line-height:15px;
}
.pha-wrapperTAB{
  display:inline-block;
  width: 100%;
  padding: 0 5px 0 5px;
}
.pha-contentTAB td{
  border-bottom: 0px dotted #E4E4E4;
  line-height:20px;
  float:left;
  width:45%;
  font-size:14px;
  padding:2px 0;
  vertical-align: middle;
}

I tried to add many styles for it but I fail all, such as:我试图为它添加许多样式,但都失败了,例如:

.fulljustify {
   text-align:justify;
 }
.fulljustify:after {
   content: "";
   display: inline-block;
   width: 100%;    
}

I don't understand why text-align justify doesn't work.我不明白为什么 text-align justify 不起作用。

You would add the justification to the same place you're styling the table cells:您可以将理由添加到您为表格单元格设置样式的同一位置:

.pha-contentTAB td {
    text-align:justify;
}

Though justify will not have any effect on one-liners.虽然 justify 不会对单线产生任何影响。 Only when it wraps to the next line, does it justify all lines except the last.只有当它换行到下一行时,它才会对齐除最后一行之外的所有行。

In your example, your CSS will work, and you need only to apply the class to each of the table cells:在您的示例中,您的 CSS 将起作用,您只需将该类应用于每个表格单元格:

<td class="fulljustify">...</td>

Try this if you want the td:first-child 's text occupies the whole line:如果您希望td:first-child的文本占据整行,请尝试此操作:
Also you should remove white-space:nowrap that you have on .pha-contentTAB tr td您还应该删除.pha-contentTAB tr td上的white-space:nowrap

 .pha-contentTAB tr td { /* white-space: nowrap; */ } .pha-contentTAB tr td:nth-child(1) { } .pha-contentTAB{ /* width:100%; */ } .pha-contentTAB tr > td:first-child{ /* width:55%; */ background-color: #CC0; text-align: justify; } .pha-contentTAB tr td:last-child{ font-weight:bold; font-size:15px; line-height:15px; } .pha-wrapperTAB{ display:inline-block; /* width: 100%; */ padding: 0 5px 0 5px; } .pha-contentTAB td{ border-bottom: 0px dotted #E4E4E4; line-height:20px; /* float:left; */ /* width:45%; */ font-size:14px; padding:2px 0; vertical-align: middle; } td:first-child::after { content: ""; display: inline-block; width: 100%; background-color: #CC0; }
 <div class="pha-wrapperTAB"> <table class="pha-contentTAB"> <tbody> <tr> <td>농 정 과</td> <td>063-454-2830</td> </tr> <tr> <td>농 촌 지 원 과</td> <td>063-454-5225</td> </tr> <tr> <td>기 술 보 급 과</td> <td>063-454-5302</td> </tr> <tr> <td>농산 물 유 통과</td> <td>063-454-3013</td> </tr> <tr> <td>농기계임대사업소</td> <td>063-454-5248</td> </tr> <tr> <td>농산 물가 공센터</td> <td>063-454-5257</td> </tr> </tbody> </table> </div>

you may what to read more about it here how-to-make-text-take-full-width-of-its-container你可以在这里阅读更多关于它的内容how-to-make-text-take-full-width-of-its-container

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM