javascript - 根据窗口大小更改列数

标签 javascript jquery html css

是否可以仅使用 CSS 更改布局,所以当窗口大小 < x 时,我将文本放在一列上,宽度为 100%,而当窗口 >= x 时,则将其设为两列,每列宽度设置为 50 %?

例如:

一栏:

first part of the example text
second part of the example text

两列:

first part of the                 second part of the
example text                       example text

最佳答案

尝试使用媒体查询 - DEMO

div {
    border: 1px solid #c00;
}

@media only screen and (min-width: 481px) {
    div { 
        -webkit-box-sizing: border-box;
           -moz-box-sizing: border-box;
                box-sizing: border-box;
        float: left;
        width: 50%; 
    }
}​

关于javascript - 根据窗口大小更改列数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12501275/

相关文章:

html - 解决缩略图的图像显示大小问题

Javascript 选择表格套索样式中的单元格

javascript - 当我单击按钮时无法弄清楚如何在 js 中向下/向上滚动 50px

html - 如何为图像设置自适应背景?

javascript - 在javascript中播放加载的文件

javascript - jQuery "split"选项?

javascript - 为什么通过函数参数从 div 获取文本不起作用?

javascript - 在下拉菜单中的 Angular 应用程序中显示 JSON 数据

javascript - 如何知道当前回调是针对哪个调用的?

javascript - 在 QML 中动态创建 ListModel