【发布时间】:2018-11-09 19:39:46
【问题描述】:
我已经使用 Flexbox 实现了以下菜单:
* {
margin: 0px;
padding: 0px;
font-family: '';
}
a {
text-decoration: none;
}
nav {
height: 70px;
width: 100%;
background-color: #5DA0E8;
display: inline-block;
}
nav .header {
font-size: 30px;
line-height: 70px;
color: white;
font-family: 'Dosis';
padding-left: 20px;
}
nav .searchbar {
background-color: #4170A3;
font-size: 18px;
padding: 4px;
border: none;
border-radius: 5px 0px 0px 5px;
vertical-align: super;
color: white;
width: 250px;
font-family: 'Dosis';
}
input:focus {
outline: none;
}
#search-icon {
width: 18px;
height: 18px;
vertical-align: super;
padding: 6px;
background-color: #4170A3;
border-radius: 0px 5px 5px 0px;
cursor: pointer;
}
nav .flex-display {
display: flex;
justify-content: center;
align-items: center;
}
<nav>
<span class="header">PLANS DU BAC</span>
<div class="flex-display">
<input type="search" name="" value="" class="searchbar" />
<img src="./ressources/media/search-icon.svg" alt="" id="search-icon" />
</div>
</nav>
我希望标题和搜索框并排显示,但不知何故 display: flex 会将搜索栏从 <div> 中踢出。
我做错了什么?
【问题讨论】:
-
请不要试图玩弄问题质量过滤器。它们存在的原因是有的。
-
尝试将“flex”属性添加到导航元素的儿童 css 规则中。 css-tricks.com/snippets/css/a-guide-to-flexbox