javascript - 仅在移动 View 中折叠列,仅在桌面 View 中折叠行

标签 javascript jquery html css

我正在使用 Yii2 开发我的 Web 应用程序。这是 html 布局:

<div class="container">
    <div class="row">
        <div class="col-md-4">
            <div class="thumbnail"> 
                <div class="caption">
                    <h3><?php echo $value['strategy_title']; ?></h3>
                    <p><?php echo $value['strategy_description']; ?></p>
                    <p><button  class="btn btn-info btn-holder" 
                                type="button" 
                                data-toggle="collapse" 
                                data-target="#<?php echo $value['strategy_title']; ?>"
                                aria-expanded="false" 
                                aria-controls="<?php echo $value['strategy_title']; ?>">
                        Know more
                    </button></p>
                    <div class="collapse" id="<?php echo $value['strategy_title']; ?>">
                        <p>
                            <!-- Here is the column chart -->
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row collapse" id="<?php echo $value['strategy_title']; ?>">
        <p>
            <!-- Here is the row chart -->
        </p>
    </div>
</div>

这只是整个页面的一部分。所以我实际使用的是带有折叠按钮的缩略图库,它切换隐藏在折叠 block 内的 Highchar.js。因此,当页面处于移动 View 状态时,我想让折叠按钮切换图表 block 在其下方,如图所示。 enter image description here否则,当页面处于桌面 View 状态时,我想使折叠按钮切换行,这是图片上的示例。 enter image description here

最佳答案

我做到了,但我想我的解决方案可能不正确。所以我制作了 2 个不同类别的按钮

<p><button  class="btn btn-info btn-holder-xs" 
                            type="button" 
                            data-toggle="collapse" 
                            data-target="#<?php echo $value['strategy_title'] . "-xs"; ?>"
                            aria-expanded="false" 
                            aria-controls="<?php echo $value['strategy_title'] . "-xs"; ?>">
                    Узнать больше
                </button></p>
                <p><button  class="btn btn-info btn-holder-md" 
                            type="button" 
                            data-toggle="collapse" 
                            data-target="#<?php echo $value['strategy_title']; ?>"
                            aria-expanded="false" 
                            aria-controls="<?php echo $value['strategy_title']; ?>">
                    Узнать больше
                </button></p>

然后我写了一些css @media

@media only screen and (max-width : 768px) {
.btn-holder-xs {
    display: block;
}
.btn-holder-md {
    display: none;
}
}
@media only screen and (min-width : 768px) {
    .btn-holder-xs {
        display: none;
    }
    .btn-holder-md {
        display: block;
    }
}

关于javascript - 仅在移动 View 中折叠列,仅在桌面 View 中折叠行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51610984/

相关文章:

html - 使用 CSS3/HTML5 旋转文本

html - 如何在 R 中使用 readHTMLTable 读取注释掉的 HTML 表格

html - div 在其他 div 内,相对于滚动向下移动( react )

javascript - 如何在javascript中添加相同类型的变量?

javascript - jQuery.Lazy() - 延迟加载具有 id 的部分的背景图像

javascript - 带有 Ember.testing = true 的 Ember.js

javascript - javascript array.length 函数的奇怪结果

javascript - 在 JavaScript 中连接函数

javascript - 是否可以让按钮标签的 CSS 监听悬停和激活?

javascript - Jquery - Internet Explorer - 语法错误