本文介绍了根据屏幕大小切换CSS类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CSS nob here ...

CSS nob here...

我正在看一个响应框架,想象我将如何完成不同的任务。

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

根据屏幕的大小,他们将类添加到body标签,例如:

Based on the size of the screen, they have classes added to the body tag such as:

.PhoneVisible,.DesktopVisible等...

.PhoneVisible, .DesktopVisible, etc...

他们还有类可以链接到按钮:

They also have classes to make links into buttons :

.btn,小按钮,med按钮,大按钮

.btn, small-button, med-button, large-button

我对如何改变CSS感到困惑。 I.E.例如:

I'm puzzled on how you would go about changing your CSS. I.E. something like:

<a href="#" class="MyButtonOptions">XXXX</>

.PhoneVisible .MyButtonOptions { btn small-button }
.TabletVisible  .MyButtonOptions { btn  med-button }
.DesktopVisible .MyButtonOptions { btn large-button }

您必须单独设置不同的选项吗?

Do you have to set the varying options individually?

.PhoneVisible .MyButtonOptions {height:30px; }

i.e. .PhoneVisible .MyButtonOptions { height:30px; } ???

推荐答案

请查看此。

另一种方式是附加resize事件某些切换代码。

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

如下所示:

HTML

<div id="body" class="limit400">
    <h1>Hey :D</h1>
</div>

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');
    }
})

关于框架,请尝试或

希望它有帮助。

这篇关于根据屏幕大小切换CSS类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:13