【问题标题】:mat-grid-list issues with aligning the second row properlymat-grid-list 正确对齐第二行的问题
【发布时间】:2019-08-27 10:19:52
【问题描述】:

我在第一个 mat-grid-list 名称和功能中有两个字段,在第二行中有搜索和清除按钮,我的问题是我想将所有按钮浮动到网格的右侧,但我做不到因此,当我给float:right; 时,它也没有显示。我希望正确对齐,我该如何实现?

<mat-grid-list cols = "7" >
      <mat-grid-tile 
      [colspan] = "1"
      [rowspan] = "1">
      <div class="form-group user">
          <label for="name">Name</label>
          <input matInput class="form-control input" [(ngModel)]="userName"matAutocomplete]="auto">
          <mat-autocomplete class="user-autocomplete" #auto="matAutocomplete">
            <mat-option *ngFor="let user of filteredUsers" [value]="user.name">
                <span class="username">{{user.name}}</span>
                <span class="usercode">{{user.code}}</span>
              </mat-option>
          </mat-autocomplete>
      </div>
      </mat-grid-tile>
      <mat-grid-tile 
      [colspan] = "1"
      [rowspan] = "1">     
       <div class="form-group function">
          <label for="function">FUNCTION</label>
          <div class="input-group">
            <mat-form-field floatLabel="never">
              <mat-select  placeholder="Select Function">
                  <mat-option *ngFor="let option of functionOptions" [value]="option.name">    
                  {{option.name}}
                </mat-option>
              </mat-select>

              <img class="material-icons chevron-down-torq select-chevron" src="assets/icons/dropdown-chevron.svg" />
            </mat-form-field>
          </div>
        </div>
      </mat-grid-tile>
  </mat-grid-list>

  <mat-grid-list cols = "7" style="float:right" >
      <mat-grid-tile 
      [colspan] = "1"
      [rowspan] = "1">
      <div class="buttons">
          <button mat-button name="search" class="search" [ngClass]="{'disable-search-btn' : !isSearch}">search</button>
      </div>
      </mat-grid-tile>
      <mat-grid-tile 
      [colspan] = "1"
      [rowspan] = "1">     
       <div class="buttons">
          <button mat-button name="clear" class="clear" [ngClass]="{'disable-clear-btn' : !isSearch}">clear</button>

        </div>
      </mat-grid-tile>
  </mat-grid-list>

css:

.按钮 { 网格间隙:20px;

.search {
  border: none;
  padding: 5px 15px;
  background-color: blue;
  color: white;
  text-transform: capitalize;
  font-weight: normal;
  cursor: pointer;

  &:hover {
    background-color: grey;
  }

  &:focus {
    background-color: dark grey;
    outline: 0;
  }
}

.clear {
  border: 1px solid lightblue;
  padding: 5px 15px;
  text-transform: capitalize;
  font-family: $roboto-font;
  font-weight: normal;
  font-size: $font-size;

  &:hover {
    background-color: red;
  }

  &:focus {
    background-color: green;
    outline: 0;
  }
}

【问题讨论】:

    标签: angular-material angular8


    【解决方案1】:

    您需要在按钮上添加style="float:right"

    <mat-grid-list cols = "7">
          <mat-grid-tile 
           [colspan] = "5"
           [rowspan] = "1">
          </mat-grid-tile>
          <mat-grid-tile 
          [colspan] = "1"
          [rowspan] = "1">
          <div class="buttons">
              <button mat-button name="search" class="search" [ngClass]="{'disable-search-btn' : !isSearch}" style="float:right">search</button>
          </div>
          </mat-grid-tile>
          <mat-grid-tile 
          [colspan] = "1"
          [rowspan] = "1">     
           <div class="buttons">
              <button mat-button name="clear" class="clear" [ngClass]="{'disable-clear-btn' : !isSearch}" style="float:right">clear</button>
    
            </div>
          </mat-grid-tile>
     </mat-grid-list>

    【讨论】:

    • 你能帮忙写一下css代码吗(如果你写过的话)
    • 我已经为按钮写过,现在包括在内。
    • 找不到合适的解决方案,但作为一种变通方法,您可以添加空的 &lt;mat-grid-title&gt;[colspan]="5"。更新上面的代码。
    • 是的,即使我觉得这是目前唯一的解决方案
    猜你喜欢
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 2021-10-31
    • 2017-11-05
    • 2019-04-09
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    相关资源
    最近更新 更多