Html 添加导航栏品牌时,使导航栏菜单居中

Html 添加导航栏品牌时,使导航栏菜单居中,html,twitter-bootstrap,Html,Twitter Bootstrap,当我添加navbar品牌时,我无法将菜单项保持在中心位置。 当我在导航栏的左侧添加徽标时,菜单项会稍微向右移动? 如何保持它的中心? 这是我的导航条形码(引导): 使用您在此处提供的代码可以快速解决问题。这可能不是最有条理的解决方案,但应该有效 你的Styles.css /* Set all contents in container to be centered automatically */ #navbarTogglerDemo01 { position: absolu

当我添加navbar品牌时,我无法将菜单项保持在中心位置。 当我在导航栏的左侧添加徽标时,菜单项会稍微向右移动? 如何保持它的中心? 这是我的导航条形码(引导):



使用您在此处提供的代码可以快速解决问题。这可能不是最有条理的解决方案,但应该有效

你的Styles.css

/* Set all contents in container to be centered automatically */
#navbarTogglerDemo01 {
  position: absolute;
  top: 0px; left: 0px;
  width: 100vw;
  max-width: 100vw;
  display: block;
  text-align: center; 
}

/* And all direct sub tags display inline block */
.navbar-brand .navbar-nav .button {
  display: inline-block;
}
另一个快速解决方案,但不是100%响应:

/* This will move each block slightly back to the left, remember to provide a unit to move left. */
.navbar-brand, .navbar-nav{
  position: relative;
  left: -10px; /* Change this to your custom amount: px % em ... etc */
}
请让我知道这是否有帮助,或者如果你有问题。
祝你好运

导航栏菜单现在居中!但我还有一个问题,当我使用你建议的样式代码时,它会破坏我在移动视图中的导航栏。导航菜单并没有隐藏和重叠在其他设计上。仅仅用一点代码是很难知道的。我能在nav旁边看到更多至少包含父容器和元素的代码吗?我只在navbar,没有别的。调用带有jquery脚本、popper和bootstrap css的简单html标记。对不起,在第二个解决方案中,而不是//应该是/*…*/。该评论取消了下一步的样式。除此之外,此解决方案应该可以在不中断实际设计的情况下工作。我已经更新了代码。
/* This will move each block slightly back to the left, remember to provide a unit to move left. */
.navbar-brand, .navbar-nav{
  position: relative;
  left: -10px; /* Change this to your custom amount: px % em ... etc */
}