【发布时间】:2018-11-24 21:09:54
【问题描述】:
我不确定为什么“元素一”没有居中。类名为“navBar”的 div 正在影响下面 div 中的文本。我不确定为什么“元素一”没有居中。当我删除“navBar” div 时,它是固定的,所以我知道这是因为这个。此外,当我删除一些属性,如 float:right 时,“元素一”会改变位置,但不会保持居中。
谢谢!
html,
body {
height: 100%;
background-color: #231C18;
font-family: 'Cabin', sans-serif;
}
body {
margin: 0;
}
.flex-container {
padding: 0;
margin: 0;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
justify-content: center;
}
.navBar {
height: 50px;
line-height: 50px;
}
.bar {
margin: 10px;
color: white;
text-decoration: none;
}
.title {
float: left;
font-size: 40px;
}
.right {
float: right;
}
.balance {
background-color: #1A1411;
border-radius: 5px;
text-align: center;
}
.bottom {
text-decoration: none;
margin: 10px;
color: #F7F7F7;
}
.flex-item {
background-color: #1A1411;
padding: 5px;
width: 90vw;
max-width: 700px;
height: 40px;
margin: 10px;
color: white;
font-weight: bold;
font-size: 2em;
text-align: center;
border-radius: 5px;
}
.ad {
height: 300px;
}
<div class="flex-container">
<div class="row">
<div class="navBar">
<a class="bar title" href="#">title</a>
<a class="bar right" href="#">three</a>
<a class="bar right" href="#">two</a>
<a class="bar right" href="#">one</a>
<a class="bar right balance" href="#">balance</a>
</div>
<div class="flex-item">element one</div>
<div class="flex-item ad">element two</div>
<div>
<a class="bottom" href="#">placeholder</a>
</div>
</div>
</div>
【问题讨论】:
标签: javascript html css flexbox