html - 将我的品牌放在我的 flexbox 顶部栏的中间

标签 html css twitter-bootstrap

我正在我的导航栏上方构建一个顶部栏,因此这不是导航栏,也不需要小屏幕上的汉堡包图标。我希望顶部栏的左端有一个图标,中间有一个品牌,右端有 2 个图标。我一直在尝试使用 flexbox 来实现我的目标,但我无法让中央品牌居中。

top bar not centering

我的代码是

<div class="container-fluid bg-light topbar">
<div id="compassicon" class="d-flex justify-content-end text-muted">
  <div class="text-muted fa fa-compass fa-2x"></div>
  <div id="townlabel" class="mr-auto p-2">Town</div>
  <div class="center">
  <p class="title-border title-text">Brand Name
  </p>
  </div>
  <div class="text-muted fa fa-user-o fa-2x"></div>
  <div class="text-muted fa fa-power-off fa-2x"></div>
</div>

CSS

.title-border {
border: 1px solid black;
border-radius: 20px;
background: #3BA7A4;


}

.title-text {
color: white !important ;
 /*font-family: 'Shrikhand', cursive;*/
font-family: 'Jura', sans-serif;
font-size: 1.5em;

}

#townlabel * {
display: inline-block;
vertical-align: middle;
font-family: 'Jura', sans-serif;

}
#compassicon {
display: inline-block;
}

.topbar {
max-height: 41px;
}

.brand-heading {
 float: none;
}

有什么想法吗?

最佳答案

你想要这样的东西吗?然后在父元素上使用 text-align:center,在文本元素上使用 display: inline-block

.title-border {
border: 1px solid black;
border-radius: 20px;
background: #3BA7A4;


}

.title-text {
color: white !important ;
 /*font-family: 'Shrikhand', cursive;*/
font-family: 'Jura', sans-serif;
font-size: 1.5em;

}

#townlabel * {
display: inline-block;
vertical-align: middle;
font-family: 'Jura', sans-serif;

}
#compassicon {
text-align: center;
}

.topbar {
max-height: 41px;
}

.brand-heading {
 float: none;
}
<div class="container-fluid bg-light topbar">
<div id="compassicon" class="d-flex justify-content-end text-muted">
  <div class="text-muted fa fa-compass fa-2x"></div>
  <div id="townlabel" class="mr-auto p-2">Town</div>
  <div class="center" style="display: inline-block;">
  <p class="title-border title-text">Brand Name
  </p>
  </div>
  <div class="text-muted fa fa-user-o fa-2x"></div>
  <div class="text-muted fa fa-power-off fa-2x"></div>
</div>

关于html - 将我的品牌放在我的 flexbox 顶部栏的中间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47318332/

相关文章:

html - CSS 避免容器调整大小以适合粗体文本

javascript - 使用 PHP 撰写但不发送电子邮件

html - 在 IE 中隐藏 CSS 元素

html - Bootstrap Navbar 非折叠(防止)

html - 如何让基于 CSS <li> 的导航栏居中?

css - window.outerHeight 使用 CSS

javascript - 在页面加载时从目录加载随机图像,无需列出文件名数组

css - Bootstrap 3-使垂直导航栏不推送网站内容

html - Bootstrap 和我的 CSS 发生冲突

html - Bootstrap 卡片中的中心进度条