【问题标题】:How to center the icon in the button如何使按钮中的图标居中
【发布时间】:2019-09-09 10:26:42
【问题描述】:

在我的 ionic 3 项目中,按钮图标没有居中。当我在浏览器中测试时,它可以正常工作,并且在 android 设备中它也可以在中心正确显示。

但只有在 ios 设备中它不会显示在中心。

上面的截图来自一个 ios 设备。因为 +,- 符号没有在中心对齐。

HTML代码:

<ion-col style="display: contents">
  <button primary large class="inbtn" (click)="decrement()">
      <ion-icon name="remove" ></ion-icon>
</button>
<h2 style="margin-left: 7px;margin-top: 0px;font-size: 2.4rem;"><b>{{currentNumber}}</b></h2>
<button primary large class="inbtn" (click)="increment()" >
  <ion-icon name="add" ></ion-icon>
</button>
</ion-col>

css:

.inbtn{
     height: 30px;
    width: 30px;
    display: inline-block;
    border-radius: 50%;
    font-size: large;
    font-weight: 500;
    margin-left: 7px;
    vertical-align: middle;
    background-color:  #d8d8d8 !important;
    text-align: center;
  -webkit-appearance: none;
    }

【问题讨论】:

    标签: html css ionic-framework ionic3


    【解决方案1】:

    这里是 css 你在找什么你可以根据你的要求固定高度和宽度;

    .inbtn{
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100px;
        height: 100px;    
    }
    

    【讨论】:

    • 出色的答案 :) 谢谢
    • @ShellZero 谢谢
    【解决方案2】:

    不要为 margin-left 使用精确的像素量,因为它可能会因使用的设备(桌面、android 或 ios)而异,最好使用百分比值作为 margin-left 和 margin-对。

    .inbtn{
             height: 30px;
            width: 30px;
            display: inline-block;
            border-radius: 50%;
            font-size: large;
            font-weight: 500;
            margin-left: 25%;
            margin-right:25%;
            vertical-align: middle;
            background-color:  #d8d8d8 !important;
            text-align: center;
          -webkit-appearance: none;
            }
    

    如果 25% 的保证金不足,请随时根据您的需要增加和更改保证金百分比。 如果这不起作用,请在下面发表评论:)

    【讨论】:

      【解决方案3】:

      html代码

       <ion-item>
         <ion-button class="center" color="success">Next</ion-button>
       </ion-item>
      

      CSS

      .center{
         margin-left: auto;
         margin-right: auto;
         display: block !important;
       } 
      

      【讨论】:

        猜你喜欢
        • 2021-08-22
        • 2021-07-21
        • 2012-01-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-11
        • 2018-02-08
        • 1970-01-01
        相关资源
        最近更新 更多