【发布时间】:2020-05-16 18:15:43
【问题描述】:
这里是初学者。出于某种原因,在我正在编码的网站中,准按钮不会在导航栏上水平对齐。我正在使用 flexbox,但即便如此,它也不会像我想要的那样对齐它们。代码似乎也没有任何问题。
.topPart {
position: fixed;
overflow: hidden;
top: 0;
margin: 0px 15px 30px 15px;
width: 1790
padding: 30px;
border: 2px solid #3cc851;
background-color: #1f1f1f;
}
.topButtons {
display: flex;
flex-flow: row wrap;
justify-content: space-around;
align-items: flex-center;
height: 15px;
width: auto;
padding: 15px;
background-color: #fff;
color: #1f1f1f;
}
.topButtons .rightButtons {
text-align: right;
margin: auto 2px auto 1500px;
}
.topButtons .leftButtons {
text-align: left;
margin: auto 2% auto 2%;
}
<div class="topPart">
<h2> Website name I don't want to share </h2> <p> Website slogan I don't want to share </p>
<!-- later, make it so that the boxes of text are lined up like how it looks in the code using css -->
<div class="topButtons">
<div class="leftButtons">
<a href="index.html" class="home">home<a>
<a href="" class="mssg">mssg board<a>
<a href="database.html" class="data">database<a>
<a href="roleplay.html" class="rp">rp<a>
</div>
<div class="rightButtons">
<a href="" class="dms">dms</a>
<a class="out">logout</a>
<a class="acc">acc</a>
</div>
</div>
</div>
右侧按钮似乎比左侧按钮低约 5 像素。我在这里完全不知所措,我的代码中似乎没有任何错误导致这种情况。应该修复它的 Flexbox 标签也不做任何事情,例如 flex-direction: row; 和 justify-content。
【问题讨论】:
-
能否请您附上相关的HTML部分
-
尝试删除此行
flex-flow: row wrap;。除此之外,按照这家伙说的做^^^ -
这能回答你的问题吗? Flexbox align items horizontally
-
不,justify-content 没有任何作用。
-
你为什么不把
width给父divtopButtons而不是给右边的margin