繁体   English   中英

如何使按钮中的图标居中

[英]How to center the icon in the button

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

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

在此处输入图像描述

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

网页代码:

<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;
    }

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

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

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;
 } 

不要为 margin-left 使用精确的像素数量,因为它会随着使用的设备(桌面,android 或 ios)而变化,因此最好使用百分比值作为 margin-left 和 margin-right。

.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% 的保证金不够,请随时根据您的需要增加和更改保证金百分比。 如果这不起作用请在下面评论:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM