【问题标题】:How move a button to the right side of the container in Material design如何在材料设计中将按钮移动到容器的右侧
【发布时间】:2017-03-28 10:14:37
【问题描述】:

我试图让一个按钮移动到容器的右侧,我使用了几种形式但我无法获得它,不知何故style="float: right;"

也许这不是一个东西,Material design,我没有前端开发经验。


 <md-toolbar color="primary">
    <span><md-icon>mood</md-icon></span>

    <span>Material in Angular 2!</span>

    <button md-icon-button style="float: left;" [md-menu-trigger-for]="menu">
      <md-icon style="float: left;">more_vert</md-icon>
    </button>
  </md-toolbar>

<button md-icon-button style="float: right;" [md-menu-trigger-for]="menu">
      <md-icon style="float: right;">more_vert</md-icon>

我想把它移到这里。我很抱歉我的英语不好。我希望你能理解我。

【问题讨论】:

    标签: angular material-design


    【解决方案1】:

    你错过了 &lt;span&gt; 文本上的类,它允许它填充空间:

    See full example here.

    .example-fill-remaining-space {
      // This fills the remaining space, by using flexbox. 
      // Every toolbar row uses a flexbox row layout.
      flex: 1 1 auto;
    }
    <md-toolbar color="primary">
      <span>Application Title</span>
    
      <!-- This fills the remaining space of the current row -->
      <span class="example-fill-remaining-space"></span>
    
      <span>Right Aligned Text</span>
    </md-toolbar>

    【讨论】:

    • 感谢您抽出宝贵的时间,我现在感觉很愚蠢,文档中有解决方案。
    • 当容器不是 md-toolbar 时,如何在 Material Design 中将按钮移动到容器的右侧?
    • 你仍然可以使用 flex。查看display: flex 的容器和flex: 1 1 auto 的孩子填写空间,如上例
    • 所以.... 这行得通,但将虚拟元素注入 HTML 是否纯粹是为了样式化,是对 1990 年实践的一种回归? (还记得人们过去常常重复 &amp;nbsp; 来实现填充吗?)如果我们正在回归 90 年代的做法,为什么不回到使用 table 进行布局? (它也有效)&lt;table style="width:100%"&gt;&lt;tr&gt;&lt;td style="text-align:left"&gt;Left&lt;/td&gt;&lt;td style="text-align:right"&gt;Right&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
    • @nothingisnecessary 我觉得你有点搞笑。没有人建议回到表格布局 - 就语义标记而言,&lt;span&gt; 对于内联元素覆盖某些区域是完全明智的。
    猜你喜欢
    • 2020-12-25
    • 2021-05-06
    • 2020-03-01
    • 2015-06-13
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 2023-02-14
    • 1970-01-01
    相关资源
    最近更新 更多