最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change CSS class if window is less than () - Stack Overflow

programmeradmin13浏览0评论

How to change a properties of a CSS class in case when browser window is shorter than 600px. Default properties are following:

.side { height:400px; width:700px; }

I want to change it to:

.side { height:300px; width:550px; }

when the window height is less than 600px.

Thanks.

How to change a properties of a CSS class in case when browser window is shorter than 600px. Default properties are following:

.side { height:400px; width:700px; }

I want to change it to:

.side { height:300px; width:550px; }

when the window height is less than 600px.

Thanks.

Share Improve this question asked Apr 12, 2013 at 17:08 bilartbilart 331 gold badge1 silver badge5 bronze badges 1
  • possible duplicate of How do I dynamically adjust css stylesheet based on browser width? – Quentin Commented Apr 12, 2013 at 17:09
Add a comment  | 

2 Answers 2

Reset to default 18

Its called a media query:

@media all and (max-height: 600px) {
    .side { height:300px; width:550px; }
}

You could try :

(function($) {

    var $sides = $('.side');

    var setCss = function() {
        if($(window).height() > 600) {
            $sides.css('width', 400).css('height', 700);
        } else {
            $sides.css('width', 300).css('height', 550);
        }
    };

    $(document).ready(function() {
        setCss();
        $(window).resize(setCss);
    );

})(jQuery);
发布评论

评论列表(0)

  1. 暂无评论