首页 > 技术文章 > HTML + CSS短标题(二,三,四文字长度)两端对齐的方式

crafts 2014-05-29 16:20 原文

今天切图碰到了一个看似好弄,却并不好弄的文本两端对齐问题。如图1-1

图1-1

我的方案

1.使用"SimSun"字体,直接打空格或者 。

比如:demo.html

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
      *{margin:0;padding:0;}
      div{width:500px;height:300px;margin:100px auto;}
      th{font-family:"SimSun";}
</style>
</head>
<body>
<div>
  <table>
    <tr>
      <th>&nbsp;&nbsp;名:</th>
      <td></td>
    </tr>
    <tr>
      <th>&nbsp;&nbsp;&nbsp;&nbsp;称:</th>
      <td></td>
    </tr>
    <tr>
      <th>&nbsp;&nbsp;&nbsp;&nbsp;码:</th>
      <td></td>
    </tr>
    <tr>
      <th>&nbsp;&nbsp;码:</th>
      <td></td>
    </tr>
    <tr>
      <th>&nbsp;&nbsp;注:</th>
      <td></td>
    </tr>
  </table>
</div>
</body>
</html>

 

这里用&nbsp是为了显眼……

 

1.2 不用字体全角空格也可以~

1.3 text-align:justify;

 

 

 

 

 

推荐阅读