繁体   English   中英

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

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

我已经尝试了所有方法,我想要标题旁边的红色按钮和按钮内的文本“ 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',
                              });

现在输出

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

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