html - 为什么文本没有与边框的中心对齐?
问题描述
<menu style="list-style:none;text-align:center;font-size:200%;border: 6px solid white;border-style:dotted;margin-top:100px;margin-left:600px;margin-right:600px;padding-top:30px;color:GhostWhite;background: rgb(0,0,0,0.8)">
Idk 为什么文本没有在框的中心对齐,即使我给了 text-align:center :(.(image attach ) 任何帮助将不胜感激!
解决方案
我的猜测是您在框中使用了一个列表 - 浏览器在 ul 元素的左侧放置了 40px 的填充。因此,请尝试将 padding::0 应用于您的 UL。
.list-wrapper {
width: 200px;
border: solid 1px #222;
margin: 0 auto;
text-align: center;
}
ul {
list-style: none;
}
.with-padding-removed {
padding-left: 0;
}
<h2>With padding removed</h2>
<div class="list-wrapper">
<ul class="with-padding-removed">
<li>Expensive breeds</li>
<li>Cat memes</li>
<li>Adopt</li>
<li>Cat pictures</li>
<li>Best breeds</li>
</ul>
</div>
<hr/>
<h2>Without padding removed</h2>
<div class="list-wrapper">
<ul class="without-padding-removed">
<li>Expensive breeds</li>
<li>Cat memes</li>
<li>Adopt</li>
<li>Cat pictures</li>
<li>Best breeds</li>
</ul>
</div>
推荐阅读
- php - 返回成功的 ping 但在发生致命错误之后
- c# - C# WPF 在套接字发送和接收数据时显示加载屏幕 C#
- java - 生成回文词
- vb.net - Sage200c SDK 在 Web 表单中崩溃
- ios - 如何使用 UIStackView 更改 UITableViewCell 的布局
- ubuntu-18.04 - Nextcloud 作为子域
- reactjs - Django-rest 框架、React JS、Axios- 发布包含图像文件的 JSON 数据
- machine-learning - 带逻辑回归的素数标识符
- git - 是否可以跟踪子模块内的文件?
- javascript - Javascript - 使用带有变量的 document.getelementbyid().value