html - 将内部 div 居中对齐

标签 html css

我有 2 个 div,内部 div 和外部 div。如何将内部div居中对齐?
这是我的源代码:

<div class="menu">
    <a href="AdminHomePage.php?id=logout">Manage Staff</a>
</div>

这是 CSS:

.menu{
    margin: 100px auto;
    z-index: 2;
    opacity: 0.9;
    text-shadow: 2px 2px 5px #000000;
    width:300px;
    border-style: solid;
    border-width: 1px;
}

.menu a{
    color: #fff;
    font-size: 35px;
    border-style: solid;
    border-width: 1px;
}

enter image description here
外层居中,内层左对齐。如何居中对齐?

最佳答案

添加文本对齐:居中;到你的父 div css

.menu{
    margin: 100px auto;
    z-index: 2;
    opacity: 0.9;
    text-shadow: 2px 2px 5px #000000;
    width:300px;
    border-style: solid;
    border-width: 1px;
    text-align: center;
}

.menu a{
    color: #fff;
    font-size: 35px;
    border-style: solid;
    border-width: 1px;
}
<div class="menu">
    <a href="AdminHomePage.php?id=logout">Manage Staff</a>
</div>

关于html - 将内部 div 居中对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29799306/

相关文章:

javascript - 如何使用 CSS-Grid 和 javascript 制作图片幻灯片

html - 给我的菜单项提供 margin 的奇怪问题

html - 图像无法正确缩放

javascript - jquery 自动提交自身

css - 如何使两个连续的 "div"标签而不是 "bleed"相互融合?

html - 内部 div 的边距影响包含 div 的边距

javascript - Bootstrap 中的分阶段捐赠表格

javascript - 滚动到顶部按钮不显示

javascript - 禁用滚动但保留滚动条 CSS

javascript - jQuery 动画 : ignore styling with css