分类的图像未垂直对齐

时间:2018-10-22 10:42:51

标签: flexbox vertical-alignment

我的flex容器包含三个div, 每个div的属性为flex-grow

我的分类图片无法在align-items: center;上使用

这是弹性容器

.top-container {
    display: flex;
    width: 100% !important;
    height: 70px;
}

这是里面的容器

.top-notifications {
    flex-grow: 6;
    background-color: #F8F9F9;
    text-align: right;
     align-items: center;
}

图像类别为

.user-picture {
    width: 35px;
    height: 35px;
    border-radius: 100%; 
    -moz-border-radius: 100%; 
    -webkit-border-radius: 100%;
}

框中的每个元素都居中对齐,但分类后的图像

1 个答案:

答案 0 :(得分:0)

body {
    margin: 0;
}

.top-container {
    display: flex;
    width: 100% !important;
    height: 70px;
}

.logo {
   background-color: #EAFAF1;
  
   display:flex;
   align-items:center;
}

.top-menu {
    background-color: #FEF9E7;
    display:flex;
    align-items:center;
}

.top-notifications {
  flex-grow: 1;
 
  display:flex;
  justify-content: flex-end;
  align-items: center;
  
  background-color: #F8F9F9;  
}


/* top menu */
.top-menu ul {
    list-style-type: none;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background-color: #FEF9E7;
    
}

.top-menu li {
    float: left;
}

.top-menu li a {
    display: block;
    color: black;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
    margin: 5px;
}

.top-menu li a:hover {
    background-color: #85C1E9;
    border-radius: 5px; 
    -moz-border-radius: 5px; 
    -webkit-border-radius: 5px;
    margin: 5px;
}
/* end top menu */

.user-picture {
    width: 35px;
    height: 35px;
    border-radius: 100%; 
    -moz-border-radius: 100%; 
    -webkit-border-radius: 100%;
}
 <div class="top-container">
        <div class="logo"><img src="images/logo.png" class="logo" />              </div>
        <div class="top-menu">
        <ul>
          <li><a class="active" href="#home">Dashboard</a></li>
          <li><a href="#news">Users</a></li>
          <li><a href="#contact">Settings</a></li>
        </ul>  
          
        </div>
          <div class="top-notifications">
             
                Notifications<i class="fa fa-bell-o fa-lg"></i>&nbsp;
                Reports<i class="fa fa-flag fa-lg"></i>&nbsp;
                <img src="images/boy.png" class="user-picture" />
          </div>
      </div>

align-items:center;用于flex父项,而不用于flex项本身。参见css flex guide