Grow your CSS skills. Land your dream job.

little tricks about RWD

  • # September 25, 2012 at 10:37 pm

    Hi Everyone,

    I have a problem with RWD, when the “media screen” applied, the css inline style will not be affected. What if i want to change the inline style, i have to use the javascript ? that means javascript callback after the “media screen” ?

    # September 25, 2012 at 10:45 pm

    Try adding an !important to the rule in your css file. That should make it override the inline rule.

    # September 25, 2012 at 10:54 pm

    Hi cnwtx,
    I don’t think this is a good solution.
    “!important” will take effect forever, then other “media” for the same css property will not take effect

    # September 26, 2012 at 1:24 am

    Instead of using `!important` you should just avoid using any inline styling at all. If you need to add styling via Javascript, then you should add a class and enter the corresponding styles in your CSS file.

    # September 26, 2012 at 3:12 am

    sometimes, we need to change the css property dynamically, let’s say using jQuery’ css() function which will update the inline style

    # September 26, 2012 at 12:55 pm

    Those are really going to be your only (good practice) choices. Either use !important, or don’t use inline. Like he said above, you should be using JS to add a class, than use the css in a css file to change the actual style on the element.

    # September 26, 2012 at 7:25 pm

    > sometimes, we need to change the css property dynamically, let’s say using jQuery’ css() function which will update the inline style

    Could you give an example of a situation where this would be preferable to just changing a class? The latter is simpler, more readable and easier code to maintain or modify. I simply don’t believe the quoted statement to be true.

    # September 26, 2012 at 7:30 pm

    The only time you’d need to use an inline style is if you’re calculating some sort of math or doing an animation.

    # September 26, 2012 at 8:00 pm

    > The only time you’d need to use an inline style is if you’re calculating some sort of math or doing an animation.

    yeah, what should I do then ?

    # September 27, 2012 at 7:06 am

    Could you post a codepen or similar? My feeling is that most problems of this sort can be resolved by reformulating your approach to the original task. In some ways it is reminiscent of [the chocolate coated banana](http://perl.plover.com./Questions3.html “More About How to Ask a Good Question”), where understanding your goal is more beneficial than producing an answer to your original question.

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".