Button text color in Extjs 4

我的梦境 提交于 2021-02-07 07:15:51

问题


I'm using Exjts 4 and i want to change the button text color. Here is my code:

{
     xtype: 'button',
     text: 'My Button',
     style:{
         color: 'red'
     }  
}  

回答1:


There is some strange behavior in Extjs 4.2.0, but there is an override possible. Give your button a class using cls:'yourClassName' property and then in CSS make a full path to span holding the text, like so: .yourClassName div a span. Also give your css property a !important value to successfuly override base class.

Ext.create('Ext.Button', {

    text: 'Click me',

    renderTo: Ext.getBody(),

    handler: function() {
        alert('You clicked the button!');
    },

    cls: 'foo'
});

and in css simply:

.foo div a span
{
    color:#ff0000 !important;
}

Here is a example.




回答2:


In case someone needs it. I do not know if it's a dirty solution but it works

{
 xtype: 'button',
 text: '<div style="color: red">My Button</div>',     
}  



回答3:


Davor Zubak shed light on a solution although it failed in my complex application. I achieved what I want by this:

  1. Button's cls: 'myButton'
  2. In my css file, define:

    .myButton .x-btn-inner {
        color: red;
        font-family: Georgia;
        font-size: large;
        font-weight: bold;
    }
    

This way it only overrides the ExtJS theme for the particular buttons who have 'myButton' cls.



来源:https://stackoverflow.com/questions/17201401/button-text-color-in-extjs-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!