代码之家  ›  专栏  ›  技术社区  ›  Mayur

内部元件的垂直对齐

  •  1
  • Mayur  · 技术社区  · 16 年前

    我有两个因素 <td> <div> 还有一些文字。我想调整一下 <部门> 顶部和文本中间 < 我该怎么做?

    编辑:应该垂直顶部对齐,而不是div内的文本。

    3 回复  |  直到 15 年前
        1
  •  0
  •   Gary Green    16 年前

    这样地?

    <html>
    <body>
        <table width="100%" height="100%" border="1">
            <tr>
                <td><div style="text-align: center;">some text</div></td>
            </tr>
        </table>
    </body>
    </html>
    

    <html>
    <body>
        <table width="100%" height="100%" border="1">
            <tr>
                <td align="center"><div style="text-align: left;">div text</div>some text</td>
            </tr>
        </table>
    </body>
    </html>
    

    请记住设置车身高度,以便可以看到垂直居中

        2
  •  1
  •   Moin Zaman    16 年前

    试试这个:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <title></title>
        <style type="text/css">
    
            html,body,h1,h2,h3,h4,h5,p,ul,li,form,button { margin:0; padding:0 }
            body { font:normal 62.5% tahoma }
    
            .my-table  { height:300px }
            .my-cell { position:relative; border:1px solid green }
            .my-div { position:absolute; top:0; left:0; border:1px solid red }
    
        </style>
    </head>
    <body>
    
        <table class="my-table">
            <tr>
                <td class="my-cell" align="center">
    
                    <div class="my-div">
                        I'm aligned to the top
                    </div>
    
                    This text is vertically centered.
    
                </td>
            </tr>
        </table>
    
    </body>
    </html>
    
        3
  •  0
  •   Vinay B R    16 年前

    默认情况下,表中的任何文本都是垂直对齐的,不确定为什么需要div。很难让内容在div中垂直对齐