角材质按钮内容未对齐

时间:2018-07-04 15:30:05

标签: html css angular angular-material angular-components

在此角度组件中,我尝试使用垫按钮显示搜索将过滤的不同类别,但是当我展开选项时,它们不出现在垫按钮下方,而是显示在按钮的左侧页面。

This is a link to the example I was trying to follow

这是组件的HTML

<div class="section categories" id="searchBtnContainer" >
   <input id="searchInput" onkeyup="filterSearch()" class="form-control form-control-dark w-50" 
type="text" placeholder="Search for a system" aria-label="Search">

   <button mat-button id="categorySelection" [matMenuTriggerFor]="menu">Menu</button>
   <mat-menu #menu="matMenu">
     <button mat-menu-item>Item 1</button>
     <button mat-menu-item>Item 2</button>
   </mat-menu>
</div>

这是组件的CSS

.section {
      width: 100%;
      padding-left: 5%;
      padding-right: 5%;
    /*  display: flex;
      flex-direction: row;*/
    }

.categories {
  justify-content: center;
  display: flex;
  flex-direction: row;
  margin: 2em .5em 1em .5em;
}

#searchInput{
  margin-right: .5em !important;
}

#categorySelection{
  margin-left: .5em !important;
}


button.active{
  color: white;
  background-color: #03A9F4;
}


.selector{
  background-color: white;
  margin-right: .5em;
  margin-left: .5em;
  text-decoration: none;
  padding:0.35em 1.2em;
  border-style: solid;
  border-width: 0.1em;
  border-color: #03A9F4;
  border-radius: 5px;
}

.selector:hover{
  color: white;
  background-color: #03A9F4;
}


body {
  font-family: Lato;

}

.fill-space {
  flex: 1 1 auto;
}

这是单击按钮时发生的屏幕截图。我正在尝试让Item1,Item2直接显示在菜单按钮下

Example of what occurs when the button is clicked

1 个答案:

答案 0 :(得分:0)

您必须像在stackblitz

中那样导入实质性主题CSS。
@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';