# CSS breaks with new custom component. What is best practice?

**URL:** <https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746>\
**Category:** ionic-v3\
**Created:** [December 29, 2017, 12:43pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746 "2017-12-29T12:43:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Catweazle101](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/catweazle101/32/115865_2.png) [@Catweazle101](https://forum.ionicframework.com/u/Catweazle101)\
**Post date:** [December 29, 2017, 12:43pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/1 "2017-12-29T12:43:14Z")

</div>

Hi

I have a general question.  
If a custom component breaks the default-ionic-css, what are you doing?  
Or maybe should we avoid this?

Scenario:

```auto
<ion-footer no-border>
  <ion-toolbar>
    <ion-buttons end>
        <button ion-button icon-only>
            <ion-icon name="alarm"></ion-icon>
        </button>
        <my-basket-button-component>
              <button ion-button icon-only>
                  <ion-icon name="basket"></ion-icon>
              </button>
        </my-basket-button-component>
    </ion-buttons>
  </ion-toolbar>
</ion-footer>

```

In the scenario above, you see for example the my-basket-button-component.  
The button looks not same like the other button within the same ion-buttons container.  
Because the additional tag…

```auto
<my-basket-button-component>

```

…breaks the default-ionic-css.

What are you doing in such a case?  
Avoid this?  
Or creating an attribute-directive instead of an custom-component (but how do I have access than to  
the child-elements).

Tips are very welcome. thx!

Cheers,  
Oliver

---

<div class="post-metadata">

**Author:** ![AaronSterling](https://avatars.discourse-cdn.com/v4/letter/a/51bf81/32.png) [@AaronSterling](https://forum.ionicframework.com/u/AaronSterling)\
**Post date:** [December 29, 2017, 12:44pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/2 "2017-12-29T12:44:43Z")

</div>

What do you mean by breaks?

---

<div class="post-metadata">

**Author:** ![Catweazle101](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/catweazle101/32/115865_2.png) [@Catweazle101](https://forum.ionicframework.com/u/Catweazle101)\
**Post date:** [December 29, 2017, 12:51pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/3 "2017-12-29T12:51:19Z")

</div>

the button within the **my-basket-button-component** looks not the same like  
the button (with alarm-icon) within the same ion-buttons container.

It seems there is an ionic-default-css defined in like:

```auto
ion-buttons{
     button {
        ...
    }
}

```

but this css to the button within an ion-buttons container, will not take affect, when there is  
an my-basket-button-component between.  
Im mean there is not something like this:

```auto
ion-buttons{
     button, my-basket-button-component {
        ...
    }
}

```

Sorry, I’m not so an expert with css stuff 😉  
P.S I will try to deliver a screenshot.

---

<div class="post-metadata">

**Author:** ![Catweazle101](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/catweazle101/32/115865_2.png) [@Catweazle101](https://forum.ionicframework.com/u/Catweazle101)\
**Post date:** [December 29, 2017, 1:08pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/4 "2017-12-29T13:08:14Z")

</div>

![iosAndAndroid](https://global.discourse-cdn.com/ionicframework/original/3X/2/4/24b859feed61b86efa5ce98c046644271fb1f8e7.png)

This example is my case shows following:

- on the left side is the ios-view on the right side is android

- the left button is the ‘normal’ button and the right button is the same button, but within the custom-component. So that means, the my-basket-button-component tag is nesting this button.

the html of the picture-examples looks like:

```auto
    <ion-buttons end>
        <button ion-button icon-only>
            <ion-icon name="basket"></ion-icon>
        </button>
        <my-basket-button-component>
              <button ion-button icon-only>
                  <ion-icon name="basket"></ion-icon>
              </button>
        </my-basket-button-component>
    </ion-buttons>

```

---

<div class="post-metadata">

**Author:** ![jamesharvey](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jamesharvey/32/116080_2.png) [@jamesharvey](https://forum.ionicframework.com/u/jamesharvey)\
**Post date:** [December 29, 2017, 5:26pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/6 "2017-12-29T17:26:38Z")

</div>

An easy solution for you:

use CSS style directly on HTML file. That will override any existing CSS classes from Ionic…

For instance:

`<button style="width: 100px; background: black; padding: 20px; font-size: 15px;">Button</button>`

Normally, it’s best to style on SCSS file but if you’re getting a problem, this should work without.

---

<div class="post-metadata">

**Author:** ![Catweazle101](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/catweazle101/32/115865_2.png) [@Catweazle101](https://forum.ionicframework.com/u/Catweazle101)\
**Post date:** [January 1, 2018, 3:55pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/7 "2018-01-01T15:55:02Z")

</div>

Hi @jamesharvey  
thx for your reply.  
yes, this would be an option. Until now I tried always to avoid creating inline-styles.  
But indeed it could be for this case an acceptable way…

---

<div class="post-metadata">

**Author:** ![jamesharvey](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/jamesharvey/32/116080_2.png) [@jamesharvey](https://forum.ionicframework.com/u/jamesharvey)\
**Post date:** [January 1, 2018, 4:04pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/8 "2018-01-01T16:04:38Z")

</div>

No prob. If things don’t work, simply add `!importnat` to your style.

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [January 1, 2018, 5:15pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/9 "2018-01-01T17:15:09Z")

</div>

@Catweazle101 I kind of have the feeling that maybe some of your local scss own classes might break what you try to achieve…

I have created a blank project and added your code and both buttons look the same (iOS und Android)

You could check out the project to have a look if you want

```
git clone https://github.com/peterpeterparker/my-basket-button

```

Let me know if I missed something. If nope, maybe try to inspect your own css classes and disable them, maybe some have a side effect?

I hope this help!

P.S.:

Wir treffen uns am 25 Januar bei der Ionic Zürich meetup hoffe ich 😉

Gruss und ein gutes Neues Jahr  
David

---

<div class="post-metadata">

**Author:** ![Catweazle101](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/catweazle101/32/115865_2.png) [@Catweazle101](https://forum.ionicframework.com/u/Catweazle101)\
**Post date:** [January 1, 2018, 8:09pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/10 "2018-01-01T20:09:48Z")

</div>

Hi @reedrichards aka David

Thanks for providing me that example on GitHub.  
I cloned it and run it on my machine.  
I saw that you missed in your example the essential part, that it should look like a toolbar.

that means your code is different at following:

```auto
<ion-footer>
  <ion-toolbar>
    <ion-buttons end>
      <button ion-button icon-only>
        <ion-icon name="basket"></ion-icon>
      </button>
      <my-basket-button></my-basket-button>
    </ion-buttons>
  </ion-toolbar>
</ion-footer>

```

You’ve forgot the **ion-toolbar** tag container.  
If you add this ion-toolbar, your example looks like following screenshot:

 ![04](https://global.discourse-cdn.com/ionicframework/original/3X/d/4/d48ce813b7f584c45776fd513481a455e29f6ec9.png)

P.S  
At the moment I only added functionality to my project.  
I didn’t add any custom css. (this comes later…yippieh!;-))

@David Zürich meetup  
Hey yeah! Freu mich drauf, ich habe mich bereits angemeldet und hoffe dass ich kommen kann. Laut Map, wohne ich ja nur ca 10min zu Fuss entfernt.  
Ok, bei mir geht es zur Zeit ein wenig länger als 10min. Grrrr…  
Hatte vor 4 Wochen eine OP am Sprunggelenk und lauf darum zur Zeit mit Krücken rum.  
Du kannst mich also gut an den Krücken erkennen. Werden wohl nicht viel mit Krücken am Meetup rumlaufen 🙂

Wünsch Dir auch noch ein gutes Neues Jahr.

Man sieht sich hoffentlich.

Oliver

---

<div class="post-metadata">

**Author:** ![Catweazle101](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/catweazle101/32/115865_2.png) [@Catweazle101](https://forum.ionicframework.com/u/Catweazle101)\
**Post date:** [January 1, 2018, 8:17pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/11 "2018-01-01T20:17:49Z")

</div>

Here my current work-arround:

I moved also the `<ion-buttons>` container into my `<my-basket-button-component>`.  
With this my button looks as expected like a toolbar-button.  
Because I assume, that the surrounding `<ion-toolbar>` can contain multiple `<ion-buttons>` tags.

P.S  
I flag it for me as an solution, but I’ll keep watching 😉

---

<div class="post-metadata">

**Author:** ![reedrichards](https://avatars.discourse-cdn.com/v4/letter/r/34f0e0/32.png) [@reedrichards](https://forum.ionicframework.com/u/reedrichards)\
**Post date:** [January 1, 2018, 8:32pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/12 "2018-01-01T20:32:45Z")

</div>

@Catweazle101 thx for pointing the missing `ion-toolbar`. So I went thru the Ionic list of issues and it looks like it’s a known issue, there is an issue regarding ion-header and ion-navbar, I guess it might be the same. If I’m not wrong, this may will be fixed in v4 according @kensodemann

I have commented this issue with this discussion and also updated to dummy repo to display the problem.

See [https://github.com/ionic-team/ionic/issues/13637](https://github.com/ionic-team/ionic/issues/13637)

P.S.: Cool fürs Meetup und eine gute schnelle Verbesserung!

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:57pm UTC](https://forum.ionicframework.com/t/css-breaks-with-new-custom-component-what-is-best-practice/116746/13 "2021-07-19T21:57:20Z")

</div>

Closed on July 19, 2021, 9:57pm UTC


