Switching CSS classes based on screen size

后端 未结 2 976
野性不改
野性不改 2020-12-01 09:17

CSS newby here...

I\'m looking at a responsive framework and imagining how I would accomplish different tasks.

Based on the size of the screen, they have class

2条回答
  •  眼角桃花
    2020-12-01 09:50

    Take a look at this https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Media_queries.

    Another way is to attach the resize event some piece of "switch code".

    Something like this: http://jsfiddle.net/s5dvb/

    HTML

    Hey :D

    CSS

    .limit400 h1 { font-size:10px; }
    .limit1200 h1 { font-size:50px; }
    

    JS

    $(window).on('resize', function() {
        if($(window).height() > 400) {
            $('#body').addClass('limit1200');
            $('#body').removeClass('limit400');
        }else{
            $('#body').addClass('limit400');
            $('#body').removeClass('limit1200');
        }
    })
    

    About the frameworks, try http://purecss.io/ or http://getbootstrap.com/

    Hope it helps.

提交回复
热议问题