html - 交换 div @media 屏幕

标签 html css

这里左边的 DIV 是可伸缩的,右边的 DIV 是固定的。代码按预期工作。唯一的问题是当屏幕尺寸低于 480px 时,右边的 DIV 会上升,而左边的 div 会下降。但我希望恰恰相反。

请参阅此处 http://jsfiddle.net/ask2asim/wcjo4zLs/

HTML:

<div class="right"></div> 
<div class="left"></div>

CSS:

.left {
    overflow: hidden;
    min-height: 50px;
    border: 2px dashed #f0f
}

.right {
    float: right;
    width: 250px;
    min-height: 50px;
    margin-left: 10px;
    border: 2px dashed #00f
}


@media screen and (max-width: 480px) {

    .left {
    width: 100%;
}

.right {
    width: 100%;
}

}

最佳答案

只需在您的标记中交换类,因为有些兄弟不会产生任何影响,它会按照您想要的方式工作。自 General sibling selector 以来,您现在无法执行您正在尝试执行的操作。不能那样应用。

The ~ combinator separates two selectors and matches the second element only if it is preceded by the first, and both share a common parent.

*{box-sizing: border-box}
.left, .right{display: inline-block; min-height: 50px}
.left {
    overflow: hidden;
    width: calc(100% - 220px); /*This is the parent width - (.right width + 10x2 marginRight bellow)*/
    border: 2px dashed #f0f;
    margin-right: 10px
}

.right {
    width: 200px;
    border: 2px dashed #00f
}
@media screen and (max-width: 480px) {
    
    .left, .right {width: 100%}

}
<div class="left"></div>
<div class="right"></div> 

另一种选择是 list 元素和 direction: ltr/rtl

关于html - 交换 div @media 屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27896559/

相关文章:

html - 在固定底部和位置粘性之间切换类

jquery - 如何使用 Jquery 按表格子标题排序

html - 拉伸(stretch)背景图像设置为 hr 标签

javascript - 让 jQuery 在我的浏览器 (chrome) 中工作的问题

javascript - 平滑滚动到

php - 如何按自定义字段日期订购 wordpress 帖子?

css - 将 "page-break-before"应用于表行 (tr)

css - firefox 中的 webfonts 和 IE 中的链接问题

php - 背景图片不会在 iOS 上显示,但在其他浏览器上可以正常显示

php - 显示 X 元素后插入新的表格行