javascript - 居中对齐 div 内的所有 p 标签
问题描述
这是我的代码,我想在所有媒体屏幕尺寸中居中对齐 div 内的所有 p 标签。我怎么做?
<div id="thankyou_block">
<p><br></p>
<p><br></p>
<div class="ticket_details">
<p style="font-weight: 500;">Your concern !</p>
<p class="case_num" style="font-weight: 500;">Please find the details: Ticket<span id="case_id"></span></p>
<p>We will take time to review your concern and take necessary actions if needed</p>
</div>
<img id="thankyou_img"
src="thankyou_opendoor.png">
<div style="display: flex; align-items: center; justify-content: center; margin-top: 30px;">
<button id="back_to_portal" onclick="back_to_portal()">Back</button>
</div>
</div>
解决方案
为此,您需要添加此代码p {text-align: center}
要更具体地应用到这段代码,您可以为每个<p>
元素提供一些类,然后{text-align: center}
只将此代码写入该类。
否则,您可以像这样添加thankyou_block
id以将其限制为仅p {text-align: center}
#thankyou_block p {text-align: center}
id="thankyou_block"
p {
text-align: center
}
<div id="thankyou_block">
<p><br></p>
<p><br></p>
<div class="ticket_details">
<p style="font-weight: 500;">Your concern !</p>
<p class="case_num" style="font-weight: 500;">Please find the details: Ticket<span id="case_id"></span></p>
<p>We will take time to review your concern and take necessary actions if needed</p>
</div>
<img id="thankyou_img" src="thankyou_opendoor.png">
<div style="display: flex; align-items: center; justify-content: center; margin-top: 30px;">
<button id="back_to_portal" onclick="back_to_portal()">Back</button>
</div>
</div>
推荐阅读
- reactjs - Laravel 8 babel 意外标记 '<' 和 ';' 预计在 className
- r - 与平均值相比,cld Tukey 字母未显示正确的组
- python - 如何以编程方式创建由可变数量的空格字符组成的字符串?
- asp.net-mvc - 如何确定服务器端性能限制 ASP.NET MVC 应用程序
- azure - Azure DNS 区域标记问题
- shell - MSYS2 中的控制台输出中断 - 使用“Shift-Ins”粘贴后未对齐的行
- google-oauth - 如何获取新的刷新 Google OAuth 令牌
- powerbi - 表如何从其关系的 1 侧的关系的 M 侧访问值?
- css - 如果使用 css 检查另一个复选框,如何隐藏一个复选框?
- python - 如何添加评论功能 Python Flask MySQL?