代码之家  ›  专栏  ›  技术社区  ›  Stefan Kendall

对齐某个文本?

  •  1
  • Stefan Kendall  · 技术社区  · 14 年前

    http://jsfiddle.net/F7BTx/

    预期输出:

    Header 1 is       Header 2           Header 3
    on two lines        
    
        [-]              [-]                [-]
    

    Header 1 is       Header 2           Header 3
    on two lines        
    
                         [-]                [-]
        [-]
    
    2 回复  |  直到 14 年前
        1
  •  1
  •   Chris Laplante    14 年前

    通常你会用 vertical-align: bottom; 而不是 vertical-align: center; ;然而,这也会带来 Header n 它也在底部。我知道,除了使用两行作为标题之外,没有其他方法可以解决这个问题。一个有 th s和一个 td s、 将第二行与 vertical-align: bottom 第一个是 垂直对齐:居中;

        2
  •  1
  •   Dagg Nabbit    14 年前

    http://jsfiddle.net/TKxrC/20/

    <style>
      th.cool_format {
        position:relative; height:64px;
      }
      th.cool_format .table_head_title {
        position:absolute;
      }
      th.cool_format .some_weird_thing {
        position:absolute;
        bottom:0px;
      }
    </style>
    <th class='cool_format'>
      <span class='table_head_title'> Header 1 is on two lines </span>
      <span class='some_weird_thing'> [-] </span>
    </th>
    

    …未测试。如果做得不好,试着给予 th.cool_format span s与 div display:block .