当位置从相对位置固定时,div的宽度会发生变化 [英] Width of div changes when position becomes fixed from relative

查看:66
本文介绍了当位置从相对位置固定时,div的宽度会发生变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当div的位置样式从相对位置更改为固定时,divtopNav的宽度会改变几个像素。我找到了一个jquery插件(http://imakewebthings.github.com/jquery-waypoints/),它可以执行我正在寻找的相同功能,但我觉得这样做有点过分。

The width of the div "topNav" changes by few pixels when its position style is changed from relative to fixed. I found a jquery plugin (http://imakewebthings.github.com/jquery-waypoints/) which can perform the same functionality I'm looking for elegantly, but I feel it is a overkill for this purpose.

编辑:我的问题是如何避免更改div大小。

My question is how to avoid changing the div sizes.

查看以下代码:

http://jsbin.com/azace5/edit

推荐答案

您需要删除页面的默认边距。这将在每个浏览器中执行:

You need to remove the page's "default margin". This will do it in "every browser":

html, body {
    margin: 0;
    padding: 0
}

参见: http://jsbin.com/azace5/2

这篇关于当位置从相对位置固定时,div的宽度会发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆