-1

I am looking for help with changing some CSS properties of my button in my Ionic app.

I want my button to look like this: enter image description here

This is how it looks like now: enter image description here

I have figured out that if I want to achieve my desired look I have to change the CSS property justify-content: center; of the DOM generated div with class button-inner to justify-content: space-between;... the problem is I don't know how to properly target this element in my SCSS file... I have tried with bellow examples as seen in the docs but nothing works...

  .button-native {
    span {
      justify-content: space-between;
    }
  }
  ion-button:scope(native) {
    span {
      justify-content: space-between;
    }
  }
  ion-button:scope(native) {
    .button-native {
      justify-content: space-between;
    }
  }
  ion-button:root(native) {
    span {
      justify-content: space-between;
    }
  }
  ion-button:root(native) {
    .button-native {
      justify-content: space-between;
    }
  }

Here is also my HTML markup for the button:

<ion-button expand="block">Add to cart <span>{{ 123 }} €</span></ion-button>

what am I missing? What am I doing wrong?

2 Answers 2

2

Don't use the ion-button tag you wont be able to change the css since it's styles lay in the shadow dom.

Instead create a button in a div and use ionic's ripple effect to simulate the button effect when clicked:

<div class="btn-container ion-activatable ripple-parent rectangle" (click)="doSomething()">
  <ion-ripple-effect></ion-ripple-effect>
  <div class="label">
    <span>Add to cart</span>
  </div>
  <div class="amount">
    <span>€</span>
  </div>
</div>

.btn-container {
  background-color: blue;
  border-radius: 8px;
  height: 40px;
  width: 240px;

  .label {
    margin: 8px;
    float: left;
    color: white;
    font-weight: 500;
  }

  .amount {
    margin: 8px;
    float: right;
    color: white;
    font-weight: 500;
  }
}
Sign up to request clarification or add additional context in comments.

Comments

-1

I don't know how to change inner-button, but since the span is flex, the solution that I've used is this:

<ion-button expand="block">Add to cart 
<div style="flex-grow: 10;"></div>
<span>{{ 123 }} €</span></ion-button>

1 Comment

Thank you! :) Altho this really works and I will use this solution for now I'd still like to see the propper way of dealing with my issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.