简体   繁体   中英

How to align text vertically in div tag, which is inside th tag?

I've tried everything, I want the red button in the center next to the heading and the text"df" inside the button. Please suggest

HTML code:

<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

You can try setting your button display property to inline-block and adding vertical-align: middle to it as well, like this:

 $(".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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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