css - 图片未垂直对齐

标签 css html vertical-alignment

.topnavigatiebar {
  width: 1500px;
  height: 100px;
  background-color: #fafafa;
  position: fixed;
  top: 0;
  overflow: hidden;
  z-index: 9;
  white-space: nowrap;
}

.topnavigatiebar img {
  float: left;
}

.topnavigatiebar #nav {
  width: 80%;
  height: 50%;
  margin-top: 25px;
  margin-left: 20px;
  float: left;
  display: block;
  text-decoration: none;
  text-align: center;
}

.topnavigatiebar #nav #sector {
  width: auto;
  height: 75%;
  float: left;
  margin: 0 15px 0 15px;
  padding: 5px 10px 5px 10px;
  border-radius: 6px;
}

.topnavigatiebar #nav #sector:hover {
  background-color: lightgrey;
  transition: 0.25s;
}

.topnavigatiebar #nav .active {
  background-color: #b7a483;
}

.topnavigatiebar #nav:visited {
  color: black;
}

.topnavigatiebar #nav #sector a {
  font-size: 20px;
  vertical-align: center;
  line-height: 40px;
  text-decoration: none;
  color: inherit;
}

#logo {
  display: inline-block;
  margin-top: auto;
  height: 100%;
  vertical-align: middle;
}

#logo img {
  background: #3A6F9A;
  vertical-align: middle;
  max-height: 100px;
  max-width: 100px;
  border-radius: 45px;
}

.right {
  float: right;
}
<div class="topnavigatiebar">
  <a href="website.php"><img src="https://imgur.com/trhdmMX"></a>
  <div id="nav">
    <div id="sector"><a href="website.php">Home</a></div>
    <div id="sector" class="active"><a href="website.php">KlantenInformatie</a></div>
    <div id="sector"><a href="website.php">Artikelen</a></div>
    <div id="sector"><a href="website.php">Instellingen</a></div>
    <div class="right">
      <div id="sector"><a href="website.php">Afmelden</a></div>
    </div>
  </div>
  <div id="logo"><img src="../Includes/Pictures/ProfielLogo.png"></div>
</div>

所以我找不到我的问题的具体答案,但我的 html 中出现了问题。

我尝试将图像垂直对齐到导航栏的中心。该图像用于个人资料图片,因此您可以看到谁登录了(登录配置还没有,但那是为了以后)。

谁能看看我的代码并告诉我我做错了什么?

它可能非常简单,我愚蠢到忘记了,但我就是想不通?

我已经尝试过这些方法,但它们并没有解决我的问题:

How to vertically align an image inside a div?

facebook photo/ image vertical align?

vertical-align image in div

编辑:这里有 2 个图片链接:

https://imgur.com/trhdmMX

最佳答案

尝试在 CSS 的 #logo img 中添加 margin-top: 20%

您也可以通过添加 display: block; margin-top: 25%;#logo img 在 CSS 中也是如此。

关于css - 图片未垂直对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53866197/

相关文章:

Css 样式不传递给表单内的标签

javascript - ajax 内容加载后重新加载灯箱

html - 将提交按钮和输入文本放在同一行

css - Div 高度不会调整以适应内容

html - 如何垂直对齐 float 图像中的替代文本?

html - 当子菜单出现在移动设备上时选择主导航中的链接

jquery - jQuery 中如何选择一个元素

jquery - 垂直滚动时水平移动 div(jquery 或 CSS3)

html - 通知未显示在特定按钮上

html - 在表格行中对齐图像和文本