[英]Max-width is changing position:fixed margin
I am having a problem properly aligning a div on the right side of the browser after the viewport has reached max-width. 视口达到最大宽度后,在将浏览器右侧的div正确对齐时出现问题。
This Codepen shows the issue. 该Codepen显示了该问题。
The problem div is .rghtlogo, which while the browser viewport is less than 1200px (the body max-width) is properly positioned with a right:4% 问题div是.rghtlogo,当浏览器视口小于1200px(主体最大宽度)时,它的正确位置为right:4%
However, when the browser viewport gets bigger than 1200px it pushes the margin in 4% of the inner right edge of the body container rather than the browser. 但是,当浏览器的视口变得大于1200px时,它会将页边距推至主体容器而不是浏览器右内边缘的4%。
I tried wrapping it in an absolute positioned div with no luck, tried floating the .rghtlogo no luck and basically have resorted to a really sloppy undesired workaround using multiple media queries to basically change the margin as the browser gets bigger. 我尝试将其包装在没有运气的绝对位置div中,尝试浮动.rghtlogo避免运气,并且基本上已经采取了一种非常草率的不良解决方法,即使用多种媒体查询来基本上随着浏览器的变大而改变边距。 However this action is not fluid.
但是,此动作并不流畅。
@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}}
I have searched with no avail as to how to fix this. 我没有搜索如何解决此问题。 Any help is greatly appreciated.
任何帮助是极大的赞赏。
Change position:fixed
to position:relative
in .rghthdr
更改
position:fixed
为.rghthdr
position:relative
and change top
and right
in .rghtlogo
to -250px
and 0
respectively. 并将
.rghtlogo
top
和right
分别.rghtlogo
为-250px
和0
。
So that .rghtlogo
is always positioned relative to .rghthdr
. 因此,
.rghtlogo
始终相对于.rghthdr
定位。
See this updated codepen : http://codepen.io/yogeshkhatri/pen/NPKQZg 请参阅此更新的Codepen: http ://codepen.io/yogeshkhatri/pen/NPKQZg
Change position:fixed to position:relative in .rghthdr and change top and right in .rghtlogo to -250px and 0 respectively.
将.rghthdr中的position:fixed固定为position:relative,并将.rghtlogo中的top和right分别更改为-250px和0。 So that .rghtlogo is always positioned relative to .rghthdr
这样.rghtlogo总是相对于.rghthdr定位
That actually kills the javascript function. 这实际上杀死了javascript函数。 Thank you tho!
谢谢你! I did end up figuring it out.
我最终弄清楚了。
Its really stupid, I realized my .nav div which is the container for all the header was set to 100% width but set with a 2.5% margin. 它真的很愚蠢,我意识到我的.nav div是所有标头的容器,其宽度设置为100%,但边距设置为2.5%。 Once I changed it to width:95% everything was fixed.
一旦将其更改为width:95%,所有内容均已修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.