Grow your CSS skills. Land your dream job.

Changing something based on the browser window width

  • # December 8, 2009 at 1:31 pm

    Hi all,
    I know there’s a simple solution but I cant find it.
    How do I change the css of something if the browser window width is less than a certain number of pixels… using jquery.

    Thanks
    Rohan Merchant

    # December 8, 2009 at 6:01 pm

    Try this

    Code:
    if( $(window).width() < 900 ) {
    console.log("Less");
    }else {
    console.log("More");
    }
# December 8, 2009 at 10:11 pm

Thanks

# December 9, 2009 at 8:59 am

You might want to add this in case the browser is resized.

Code:
// On Resize
$(window).resize(function() {
if( $(this).width() < 900 ) {
console.log("Less");
}else {
console.log("More");
}
});
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

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