Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing background color of Ionic ion-item in CSS

Tags:

I have added the following code style="background-color: #C2A5A5 !important. But that has not worked for me. how can I add background color to ion-item?Thanks in advance.

<ion-item class="item-remove-animate item-avatar item-icon-right" style="background-color: #C2A5A5 !important" ng-repeat="detail in details" type="item-text-wrap" ng-controller="ChatsCtrl"  ng-click="openShareModel(detail)">     <img ng-src="{{profilepic.profileimageurl}}">      <h2>{{detail.date | date :'fullDate'}}</h2>     <h2>{{detail.title}}</h2>     <p>{{detail.description}}</p>     <i class="icon ion-chevron-right icon-accessory"></i>      <ion-option-button class="button-assertive" ng-controller="ChatsCtrl" ng-click="remove(detail.id)">       Delete     </ion-option-button>    </ion-item> 
like image 750
Rajitha Perera Avatar asked Aug 02 '15 14:08

Rajitha Perera


People also ask

How do I change the background color in Ionic toolbar?

Styling the Ionic 5 Toolbar ( ion-toolbar ) $toolbar-background: #123456; $toolbar-border-color: #123456; $toolbar-text-color: #123456; $toolbar-active-color: #123456; $toolbar-inactive-color: #123456; Just put them in the variables. scss file and change their values to your desired colors.

Can we change background color in CSS?

You can change the background color of an HTML element using the background-color CSS property and giving it a value of a color.


1 Answers

Ionic is injecting an element inside the <ion-item> giving the element a structure of:

<ion-item>   <div class="item-content">   </div> </ion-item> 

The Ionic CSS contains a CSS property:

.item-content {   background-color:#ffffff; } 

The inline CSS you added is being applied to the element behind the element with the #ffffff background, so you can't see your background color.

Apply the background color to the .item-content element, as @ariestiyansyah recommended by adding the following CSS to the Ionic CSS file, or create a custom CSS file and include a <link> to it in the header, with the following:

.item .item-content {   background-color: transparent !important; } 

Here's the working demo.

like image 65
Brett DeWoody Avatar answered Sep 20 '22 09:09

Brett DeWoody