简体   繁体   English

Ionic 按钮内的图像

[英]Image inside the Ionic button

Good morning, I'm trying to put an image inside an ionic button, but I'm not having success, I've tried everything, does anyone have any correct solution for native buttons?早上好,我正在尝试将图像放在离子按钮中,但我没有成功,我已经尝试了所有方法,是否有人对本机按钮有任何正确的解决方案?

<ion-button
  class="home-link link-2"
  style="background-image:url('img/myImage.jpg'); background-size:cover" 
  routerLink="/schedule"
>
  AGENDA
</ion-button>

Make a selector class and add your background image to it:制作一个选择器 class 并将您的背景图像添加到其中:

 #AddImg { background-image: url(' http://placekitten.com/301/301'); height: 100px; width: 100px; }
 <ion-button class="home-link link-2" id="AddImg" style=" background-size:cover" routerLink="/schedule">AGENDA</ion-button>

OR或者

something like this:像这样的东西:

 ion-button { background-image: url(' http://placekitten.com/301/301'); }
 <ion-button class="home-link link-2" id="AddImg" style=" background-size:cover" routerLink="/schedule">AGENDA</ion-button>

Your button is colored by default, try to add the property color="none" to your ion-button object, like this:您的按钮默认是彩色的,尝试将属性color="none"添加到您的ion-button object,如下所示:

<ion-button
  color="none" // <-- Add this line
  class="home-link link-2"
  style="background-image:url('img/myImage.jpg'); background-size:cover" 
  routerLink="/schedule"
>
  AGENDA
</ion-button>

So that you can see the image underneath the default background color.这样您就可以在默认背景颜色下看到图像。 Hope this helps !希望这可以帮助 !

the below code just worked for me in Ionic 4.下面的代码在 Ionic 4 中对我有用。

<ion-button color="clear" class="home-link link-2" routerLink="../../tab2">
  <ion-img src='path/to/image.png'></ion-img>
</ion-button>

The image would be displayed only within the button.图像将仅显示在按钮内。

If you would like to display a large image, you could edit the style for the ion-button based on your need.如果您想显示大图像,您可以根据需要编辑ion-buttonstyle

The routerLink you are providing needs to be aligned based on the current page you are in, or else you could give the absolute path of the component based on the routing module.您提供的routerLink需要根据您所在的当前页面对齐,否则您可以根据路由模块给出组件的绝对路径。

Hope that helps!希望有帮助!

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

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