【问题标题】:Hide/Show div with @mediaquery使用@mediaquery 隐藏/显示 div
【发布时间】:2014-03-27 13:50:37
【问题描述】:

当用户使用移动设备查看网站时,我有一个 3 col 幻灯片并隐藏 2 col。这是有效的,我尝试添加另一个 col,然后决定不添加。从那以后这不起作用,我似乎不明白为什么。

我的代码:

<div id="rightCol">
    <div class="slideshowR">
        <img src="../images/slideshow/kettle.jpg">
        <img src="../images/slideshow/zucchini-flower.jpg">
        <img src="../images/slideshow/truffle.jpg">
    </div>
</div>

CSS:

.slideshowR {
    height: 370px;
    width: 250px;
    margin: auto;
}   

#leftCol {
    width: 205px;
    float: left;
    margin: 0;
    padding: 0;
    display: none;
}

#centerCol {
    width: 150px;
    float: left;
    margin: 0;
    padding-left: 10px;
    display: none;
}

#rightCol {
    width: 250px;
    float: left;
    margin: 0;
    padding-left: 10px;
}

@media only screen and (min-width: 769px) {
    #leftCol {
        display: block !important;
    }

    #centerCol {
        display: block !important;
    }

    #rightCol {
    }
}

【问题讨论】:

  • 在移动设备中应该隐藏哪个列?哪个列应该显示在桌面上?如果方向明确,这很容易做到
  • 在桌面上显示所有 3 列。在移动设备中,我只想显示右列
  • @user3317435 更新了答案以在 739px 宽度下显示右侧而不是左侧

标签: css media-queries multiple-columns


【解决方案1】:

我会这样做

#leftCol {
    width: 205px;
    float: left;
    margin: 0;
    padding: 0;
}

#centerCol {
    width: 150px;
    float: left;
    margin: 0;
    padding-left: 10px;
}

#rightCol {
    width: 250px;
    float: left;
    margin: 0;
    padding-left: 10px;
}

/* hide center and left in mobile */
@media only screen and (max-width: 769px) {
    #leftCol, #centerCol {
        display: none;
    }
}

【讨论】:

  • 对于移动设备:#leftCol、#centerCol、#rightCol { 显示:无; } 用于桌面:#leftCol { 显示:块; } #centerCol { 显示:块; } #rightCol { 显示:块; } #rightCol2 {显示:块; } #mobSlide { 显示:无; }
  • 猜你喜欢
    • 1970-01-01
    • 2011-08-20
    • 2014-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    相关资源
    最近更新 更多