简体   繁体   English

标题中的列表项目不是很中心(使用Flexbox)

[英]List items in header are not quite centered (using Flexbox)

If viewed on desktop it seems fine, but on mobile there is definitely uneven spacing on the left and right side of the list items. 如果在桌面上查看它似乎很好,但在移动设备上,列表项的左侧和右侧肯定存在不均匀的间距。

Note: list items are pink. 注意:列表项是粉红色的。

Any help in spacing these evenly would be much appreciated! 任何帮助均匀间隔这些将非常感谢!

在此输入图像描述

Link to codepen: https://codepen.io/connorocampo/pen/OoRygB?editors=1100 链接到codepen: https ://codepen.io/connorocampo/pen/OoRygB editors = 1100

<ul id="flex-nav">  
  <li><a href="#skills" class="nav-link">Skills</a></li>
  <li><a href="#certified" class="nav-link">Certified</a></li>
  <li><a href="#hire" class="nav-link">Hire!</a></li>
</ul>  

<style>
#flex-nav{
  display: flex;
  justify-content: space-evenly;
  margin-bottom: 0px;
  padding-bottom: 5px;
}
</style>

Add padding-left: 0 to your container ( #flex-nav ). padding-left: 0添加到容器中( #flex-nav )。

List elements come with default padding (or margin). 列表元素带有默认填充(或边距)。

This is your code in Chrome: 这是您在Chrome中的代码:

在此输入图像描述

Also, you can avoid the problem altogether and simplify your code like this: 此外,您可以完全避免这个问题并简化您的代码,如下所示:

 #flex-nav{ display: flex; justify-content: space-evenly; margin-bottom: 0px; padding-bottom: 5px; } 
 <nav id="flex-nav"> <a href="#skills" class="nav-link">Skills</a> <a href="#certified" class="nav-link">Certified</a> <a href="#hire" class="nav-link">Hire!</a> </nav> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM