Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExtJS: Put size/margin/padding in Component or External .css File?`

Tags:

extjs

Is there a 'best practice' when it comes to specifying size/margin/padding info in components (i.e., adding it programmattically via JavaScript) vs. putting it in external CSS files?

I've gotten into the habit of doing the former. But I can see some people arguing for putting that stuff in an external CSS file so that you could, in theory, modify layouts (size/margin/padding) in different themes.

What do others think? Is there an established best practice?

Thanks.

like image 984
Clint Harris Avatar asked Jun 14 '11 19:06

Clint Harris


1 Answers

The best approach I find is to assign classes to all your components and style them in your CSS files. For example...

var styledPanel = new Ext.Panel({
    cls: 'panel-styled',
    items: [ ]
});

And then have a CSS rule to style it...

.styled-panel {
    background-color: #e7e7e7;
}

Obviously, this allows you to group component styles together as well.

As a side note, I usually use the bodyStyle property to add formatting which isn't likely to change, for example... most Windows need padding and this isn't likely to change frequently so I stick that in the bodyStyle property.

var paddedWindow = new Ext.Window({
    title: 'Window',
    bodyStyle: 'padding: 4px;'
});
like image 141
JamesHalsall Avatar answered Sep 27 '22 21:09

JamesHalsall