从这个布局开始:http: //codepen.io/RebelOne/pen/wodbpR
.navbar {
display: flex;
justify-content: space-between;
Run Code Online (Sandbox Code Playgroud)
当我添加位置:固定到导航栏时,它会向下折叠并且不会填充包装器的宽度.有谁知道如何解决这一问题? http://codepen.io/RebelOne/pen/bBWyLZ?editors=1100
.navbar {
display: flex;
justify-content: space-between;
background-color: yellow;
position: fixed;
top: 0;
z-index: 99;
}
Run Code Online (Sandbox Code Playgroud)
显示:弯曲和位置:固定不顺利.
你可以做一点改变,让它看起来像这样
请查看以下代码段
/* Clear formatting*/
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
/* Remove formatting from links*/
a {
color: inherit;
text-decoration: none;
}
/* Set a max width to the content*/
.wrapper {
max-width: 960px;
margin: 0 auto;
background-color: pink;
display: flex;
flex-direction: column;
/*height: 100vh; */
}
.parent {
position: fixed;
top: 0;
left: 0;
margin: auto;
width: 100%;
}
.navbar {
display: flex;
justify-content: space-between;
background-color: yellow;
/* */
}
.logo {
padding: 20px;
}
.menu {
display: flex;
align-items: center;
}
.menu ul {
display: flex;
justify-content: flex-end;
align-items: center;
list-style: none;
background-color: grey;
}
.menu li {
padding: 20px;
margin-left: 20px;
background-color: orange;
color: rgba(255, 0, 0, 0.9);
font-size: 16px;
font-weight: bold;
}Run Code Online (Sandbox Code Playgroud)
<div class="parent">
<div class="navbar">
<div class="logo">
<picture>
<img src="http://fillmurray.com/50/50" alt="logo">
</picture>
</div>
<div class="menu">
<ul>
<li><a href="#home">Home</a>
</li>
<li><a href="#about">About</a>
</li>
<li><a href="#contact">Contact</a>
</li>
</ul>
</div>
</div>
</div>
<div class="wrapper">
<div style="height: 2000px"></div>
</div>Run Code Online (Sandbox Code Playgroud)
希望能帮助到你
| 归档时间: |
|
| 查看次数: |
9529 次 |
| 最近记录: |