1

is there a way to add jquery ui classes into my own css file per element, IE:

       input { 
               ui-corner-all  /*  <- JQuery UI class */ 

              }

as opposed to adding the class to every input, IE:

       <input name="myinput" type="text" class="ui-corner-all"  value="" />
3
  • Are you meaning that you would like to just apply the ui-corner-all class attributes directly to input such that you can remove the class name from the actual input element? Commented Jan 17, 2013 at 20:59
  • You could duplicate the CSS definition from the UI css file and put it in your own css file, applied to any element you want. Would that work for you? Commented Jan 17, 2013 at 21:00
  • 2
    You can check out LESS: here a similar question stackoverflow.com/questions/1065435/… Commented Jan 17, 2013 at 21:00

4 Answers 4

1

You can check out LESS, here is a very similar question on SO Can a CSS class inherit one or more other classes?

LESS is an extension for CSS a great level of abstraction with variables, nested rules, function, operations, etc

Sign up to request clarification or add additional context in comments.

1 Comment

how is the browser compatibility with your answer compaired to the javascript answer below?
0

You can use the jQuery .addClass method to add a class to elements at any time, including page load, such as:

$(function() {
  $(input).addClass('ui-corner-all');
});

This would add the ui-corner-all class to every input element in the html when the page loads. If you would like to select only certain elements on the page, use a more specific selection, such as:

$(function() {
  $('#myInput').addClass('ui-corner-all');
});

This will add the ui-corner-all class to all of the elements on the page that have the ID of myInput.

1 Comment

Granted, this is not what I was asking for, it worked better for me! Thx
0

You might want to look into checking out Sass. This will give you the option to extend css classes to your own classes via @extend.

This is a handy Sass + Compass video

Then after you can do this

This way, you don't have to depend on javascript to add classes. It's all done through css.

Hope this helps!

Comments

0

You could also use a preprocessor like LESS to achieve this. You would have to save your ui.css as ui.less and then you could do something like this:

@import url(ui.less);

input {
  .ui-corner-all;
}

After compilation of your less to css, it would take all the styles of the ui-corners-all class and apply them to your inputs. And that is just one of the many advantages of using a css preprocessor. It is really worth looking into and is not very hard to learn if you are familiar with css. You can find more info here: http://lesscss.org/

Comments

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.