【问题标题】:How to align text vertically in div tag, which is inside th tag?如何在 th 标签内的 div 标签中垂直对齐文本?
【发布时间】:2018-08-23 13:04:23
【问题描述】:

我已经尝试了所有方法,我想要标题旁边中间的红色按钮和按钮内的文本“df”。请推荐

HTML 代码:

<th style="width:11.5%;font-weight:bold;text-align:center;" valign="middle">
Table heading1 
<div id="myButton1" class='myButtons' style=" text-align: left;" >df</div>
</th>

CSS:

$(".myButtons").button().css({ 'width': '15%','height' : '10px','line-height': '10px',
                               'padding-top': '0px',
                               'padding-bottom': '0px',
                               'font-size': '11px',
                               'background':'#ff0000',
                               'font-family': 'Century Gothic, sans-serif', 
                               'text-align':'left',
                               'border-color':'#ff0000',
                               'border-radius':'2px',
                              });

Output right now

【问题讨论】:

    标签: jquery html css button


    【解决方案1】:

    您可以尝试将您的按钮 display 属性设置为 inline-block 并将 vertical-align: middle 添加到它,如下所示:

    $(".myButtons").css({
      'width': '15%',
      'height': '10px',
      'line-height': '10px',
      'display': 'inline-block',
      'padding-top': '0px',
      'padding-bottom': '0px',
      'font-size': '11px',
      'background': '#ff0000',
      'font-family': 'Century Gothic, sans-serif',
      'text-align': 'left',
      'border-color': '#ff0000',
      'border-radius': '2px',
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <table>
      <tr>
        <th style="width:11.5%;font-weight:bold;text-align:center;" valign="middle">
          Table heading1
          <div id="myButton1" class='myButtons' style=" text-align: left;">df</div>
        </th>
      </tr>
    </table>

    【讨论】:

    • 不知何故我仍然得到相同的输出,我只是增加了高度以使文本看起来好像它在
      内。
    • 你能发一个sn-p,这样我就可以看到现场发生了什么?
    猜你喜欢
    相关资源
    最近更新 更多
    热门标签