【发布时间】:2016-01-06 12:15:24
【问题描述】:
我在使用媒体查询将 div 定位到右侧时遇到问题。
HTML
<div class="container">
<div class="left"></div>
</div>
CSS
body,html { height:100%; }
.container {
width:1000px;
height:100%;
background:#eee;
position:relative;
}
.left {
height:100%;
width:200px;
background:orange;
position:absolute;
left:0;
}
@media only screen and (max-width: 700px) {
.left {
position:absolute !important;
right:0 !important;
}
}
左侧 div 绝对位于左侧。当我的媒体查询以 700px 宽度触发时,我希望将同一个 div 绝对定位在右侧。
问题是它不会这样做!我尝试使用!重要。我试图重申媒体查询中的立场。没有!
奇怪的是,如果我从 div 绝对定位在右侧开始,而对于媒体查询,则将 div 绝对定位在左侧。有用! 什么?为什么?
DIV 绝对位于左侧,通过媒体查询将 DIV 置于右侧。
不工作
DIV 绝对位于右侧,使用媒体查询将 DIV 置于左侧。
这工作
如何让它工作?触发媒体查询时,如何让绝对左侧的 div 将自己绝对定位到右侧?
【问题讨论】:
标签: css responsive-design media-queries