我试图为网站制作导航栏。我试图将我的链接文本水平居中在div中。 <table>
<tr>
<td class="col-1">One</td>
<td class="col-2">Two</td>
</tr>
<tr>
<td class="col-3">Three</td>
<td class="col-4">Four</td>
</tr>
</table>
没有做到这一点,text-align: center;
和align-items: center;
都没有。有什么提示吗?
justify-content: center;
&#13;
#nav {
display: flex;
flex-direction: row rtl;
border-top: 3px dotted #594027;
border-bottom: 3px dotted #594027;
width: 100%;
align-items: center;
justify-content: center;
}
.navbox {
flex-wrap: wrap;
background-color: #594027;
width: 125px;
margin: 5px;
padding: 5px;
}
.navbox a {
display: inline-block;
color: white;
padding: 3px;
margin-right: auto;
margin-left: auto;
text-decoration: none;
}
&#13;
答案 0 :(得分:0)
您可以控制来自父级的文字,因为您需要将text-align:center
添加到#nav
#nav {
display: flex;
flex-direction: row rtl;
border-top: 3px dotted #594027;
border-bottom: 3px dotted #594027;
width: 100%;
align-items: center;
justify-content: center;
/* Add text-align to Parent */
text-align:center;
}
.navbox {
flex-wrap: wrap;
background-color: #594027;
width: 125px;
margin: 5px;
padding: 5px;
}
.navbox a {
display: inline-block;
color: white;
padding: 3px;
margin-right: auto;
margin-left: auto;
text-decoration: none;
}
<div id="nav">
<div class="navbox">
<a href="index.html">Home</a>
</div>
<div class="navbox">
<a href="resume.html">Resumé</a>
</div>
<div class="navbox">
<a href="coursework.html">Coursework</a>
</div>
<div class="navbox">
<a href="accomplishments.html">Accomplishments</a>
</div>
<div class="navbox">
<a href="experience.html">Experience</a>
</div>
<div class="navbox">
<a href="blog.html">Blog</a>
</div>
</div><!--nav->