0

I have this css:

@media only screen and (max-height: 620px) {
#howto img {
    margin-left:150px;
}
.boilerplate {
    text-align:right;
}
.footer .boilerplate .links {
    float:right;
}
.footer {
    text-align:right !important;
}

}

and I want to do this css with jQuery. How can I do it?

2
  • i cant explain why, i just need to do it Commented Apr 12, 2012 at 17:08
  • This question does make some sense since some CMS's strip out <style> tags when placed in the editor but don't strip javascript/jQuery. If you don't have access to change the code as a developer, sometimes the only way to make a page look right is to use a jQuery css workaround...granted it's not at all a good idea to do consistently. It's best to have a developer with access make the style changes to the stylesheet. Commented Jan 20, 2014 at 19:43

4 Answers 4

2

try this:

$("document").ready(function(){  
    if ($(window).width() <= 620) {
      $("#howto img").css("margin-left", "150");
      $(".boilerplate").css("text-align", "right");
      $(".footer .boilerplate .links").css("float", "right");
      $(".footer").css("text-align", "right");
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

for example

$("document").ready(function(){
  $(".boilerplate").css("text-align","right");
});

But you must then make every style in jquery. Another possibility would be to make the styles completely database driven and loop through.

2 Comments

yes, i know that but how to do this @media only screen and (max-height: 620px) { ?
you don't need to do it over media. In jquery you can get the window sizes directly. You set it then in an if
0
$(window).resize(function(){  
    if ($(window).width() <= 620) {
      $("#howto img").css("margin-left", "150");
      $(".boilerplate").css("text-align", "right");
      $(".footer .boilerplate .links").css("float", "right");
      $(".footer").css("text-align", "right");
    }else{    /*Asuming you didn't have any inline style before*/
         $('#howto img,.boilerplate,.footer,.footer .boilerplate .links').removeAttr('style'); 
         /*To restore de original styles*/
    }
});

2 Comments

This way it will be applied everytime the window is resized. not only on document.ready
But if you do not need support for older browsers i just don't understand why you need to do this in Jquery
0

Have you ever tried beansoup? They have a nice CSS to jQuery converter.

Sometimes, there are some problems with the conversions, but most of them are great.

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.