【问题标题】:Problem to align all buttons right position对齐所有按钮正确位置的问题
【发布时间】:2021-02-07 07:49:00
【问题描述】:

我使用 angular material(10.2.5) 工具栏组件,我想让我的三个按钮向右,但我不能

<mat-toolbar color="primary">
    <mat-toolbar-row>
      <h3 [style.color]="'white'">Portail admin</h3>
  <div class="parent">
    <div class="children right-children">
      <div class="child"><a mat-flat-button >Liste des livres</a></div>
      <div class="child"><a mat-flat-button >Ajouter un livre</a></div>
      <div class="child"><a mat-flat-button >Deconnexion</a></div>
    </div>
  </div>
    </mat-toolbar-row>
  </mat-toolbar>

.parent {
    display: flex;
    width: 100%;
    height: 100px;
    align-items: center; 
    justify-content: space-between; 
  }
  
  .children {
    display: flex;
  }
  
  .child {
    margin: 0 5px;
    padding: 0 5px;
    font-size: 10px;
    color: #000;
  }

有什么想法吗? 我想将我的三个按钮对齐到工具栏的左侧,但我真的做不到。

对于我的 html 和 css 代码,我使用了 flexbox css。

【问题讨论】:

标签: html css flexbox angular-material


【解决方案1】:

添加这个

  .child {  
    display: inline-block;
    margin: 0 5px;
    padding: 0 5px;
    font-size: 10px;
    color: #000;
  } 
  .right-children{
    position: relative;
    bottom:80px;   
    display: inline-block;
    margin-left:1000px ;
  }

结果:https://i.stack.imgur.com/6JD3h.png

【讨论】:

    【解决方案2】:

    我尽量少接触你的 css 并使用你提到的使用它们而不是网格的 flex。

    基本上,您的 mat-toolbar-row 将是水平弯曲的。你的父类将有justify-content: end;

    mat-toolbar-row {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between; 
    }
    
    h3 {
      white-space: nowrap;
    }
    
    .parent {
        display: flex;
        flex: 1;
        height: 100px;
        align-items: center; 
        justify-content: end; 
        white-space: nowrap;
      }
      
      .children {
        display: flex;
      }
      
      .child {
        margin: 0 5px;
        padding: 0 5px;
        font-size: 10px;
        color: #000;
      }
    <mat-toolbar color="primary">
      <mat-toolbar-row>
        <h3 [style.color]="'white'">Portail admin</h3>
        <div class="parent">
          <div class="children right-children">
            <div class="child"><a mat-flat-button >Liste des livres</a></div>
            <div class="child"><a mat-flat-button >Ajouter un livre</a></div>
            <div class="child"><a mat-flat-button >Deconnexion</a></div>
          </div>
        </div>
      </mat-toolbar-row>
    </mat-toolbar>

    【讨论】:

      【解决方案3】:

      回答

      .parent {
          display: flex;
          width: 100%;
          height: 100px;
          align-items: center; 
          justify-content: space-between; 
          
        }
        
        .children {
          display: flex;
      }
        
        .child {
          margin: 0 5px;
          padding: 0 5px;
          font-size: 10px;
          color: black;
        }
      
      .right-children{
        position:absolute;
        right:0;
      }
      <mat-toolbar color="primary">
          <mat-toolbar-row>
            <h3 [style.color]="'white'">Portail admin</h3>
        <div class="parent">
          <div class="children right-children">
            <div class="child"><a mat-flat-button >Liste des livres</a></div>
            <div class="child"><a mat-flat-button >Ajouter un livre</a></div>
            <div class="child"><a mat-flat-button >Deconnexion</a></div>
          </div>
        </div>
          </mat-toolbar-row>
        </mat-toolbar>

      添加:

      .right-children{
      position:absolute;
      right:0;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-24
        • 2020-02-16
        • 2017-05-07
        • 1970-01-01
        • 2013-11-11
        相关资源
        最近更新 更多