简体   繁体   English

如何在标签内的div标签中垂直对齐文本?

[英]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. 我已经尝试了所有方法,我想要标题旁边的红色按钮和按钮内的文本“ df”。 Please suggest 请建议

HTML code: 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: 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: 您可以尝试将按钮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> 

如何访问`<div> `标签内的`<p> `标签? </p></div><div id="text_translate"><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"> $("p div").click(function() { $(this).css({ "color": "#F00", "font": "bold 20px verdana", "background-color": "#0FF" }); });</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt; &lt;p&gt;Hello&lt;div&gt; World!&lt;/div&gt;&lt;/p&gt;</pre></div></div><p></p><p> 当我单击“世界”文本时,什么也没有发生,当我检查元素时,它说:</p><pre class="lang-html prettyprint-override"> &lt;p&gt;Hello&lt;/p&gt; &lt;div&gt; World&lt;/div&gt; &lt;p&gt;&lt;/p&gt;</pre><p> 注意那些&lt;p&gt;标签。 怎么会这样?</p></div> - How to access a `<div>` tag inside a `<p>` tag?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何垂直对齐div文本? - How to vertically align div text? 如何在div中垂直和水平对齐img? - How to vertically AND horizontally align img inside div? 在文本标签内添加div - Add a div inside the text tag 如何在表格的 div 中垂直居中对齐文本? - How to align text vertically center in div on table? 如何在已经在th标签中工作的td标签中设置大小调整? - how to set resizing in td tag which is already working in th tag? 如何访问`<div> `标签内的`<p> `标签? </p></div><div id="text_translate"><p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"><div class="snippet-code"><pre class="snippet-code-js lang-js prettyprint-override"> $("p div").click(function() { $(this).css({ "color": "#F00", "font": "bold 20px verdana", "background-color": "#0FF" }); });</pre><pre class="snippet-code-html lang-html prettyprint-override"> &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt; &lt;p&gt;Hello&lt;div&gt; World!&lt;/div&gt;&lt;/p&gt;</pre></div></div><p></p><p> 当我单击“世界”文本时,什么也没有发生,当我检查元素时,它说:</p><pre class="lang-html prettyprint-override"> &lt;p&gt;Hello&lt;/p&gt; &lt;div&gt; World&lt;/div&gt; &lt;p&gt;&lt;/p&gt;</pre><p> 注意那些&lt;p&gt;标签。 怎么会这样?</p></div> - How to access a `<div>` tag inside a `<p>` tag? 如何在转发器的div标记内生成不在数据库中的动态值 - how to generate dynamic values inside div tag in repeater which are not in database 如何显示表tr td标签内的div? - How to show div which is inside table tr td tag? 删除 div 内“a”标签的“rel”属性 - Remove 'rel' attribute of 'a' tag which is inside a div 如何以此为目标标记内部div? - How to target tag a inside div with this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM