【问题标题】:Max-width is changing position:fixed margin最大宽度正在改变位置:固定边距
【发布时间】:2015-01-08 21:45:25
【问题描述】:

在视口达到最大宽度后,我无法正确对齐浏览器右侧的 div。

This Codepen shows the issue.

问题 div 是 .rghtlogo,当浏览器视口小于 1200px(body 最大宽度)时,它以 right:4% 正确定位

但是,当浏览器视口大于 1200 像素时,它会将边距推向正文容器内右边缘的 4%,而不是浏览器。

我尝试将它包装在一个绝对定位的 div 中,但没有运气,尝试浮动 .rghtlogo 没有运气,并且基本上采用了一个非常草率的不受欢迎的解决方法,使用多个媒体查询来基本上随着浏览器变大而改变边距。然而这个动作并不流畅。

@media (min-width:1201px){.rghtlogo{margin-right:3% !important}}
@media (min-width:1216px){.rghtlogo{margin-right:1.5% !important}}
@media (min-width:1230px){.rghtlogo{margin-right:.75% !important}}
@media (min-width:1251px){.rghtlogo{margin-right:0% !important}}
@media (min-width:1256px){.rghtlogo{margin-right:-1% !important}}

我搜索了如何解决这个问题,但无济于事。非常感谢任何帮助。

【问题讨论】:

    标签: javascript css


    【解决方案1】:

    .rghthdr 中将position:fixed 更改为position:relative
    并将.rghtlogo中的topright分别更改为-250px0

    这样.rghtlogo 总是相对于.rghthdr 定位。
    请参阅此更新的代码笔:http://codepen.io/yogeshkhatri/pen/NPKQZg

    【讨论】:

      【解决方案2】:

      在 .rghthdr 中更改位置:固定到位置:相对 并将 .rghtlogo 中的 top 和 right 分别更改为 -250px 和 0。 所以 .rghtlogo 总是相对于 .rghthdr 定位

      这实际上杀死了 javascript 函数。谢谢你!我确实最终弄明白了。

      这真的很愚蠢,我意识到我的 .nav div 是所有标题的容器,设置为 100% 宽度,但设置了 2.5% 的边距。一旦我将其更改为 width:95%,一切都已修复。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-28
        • 2017-05-16
        • 2018-12-13
        • 1970-01-01
        相关资源
        最近更新 更多