职位在 Firefox 中工作良好,在其他人中不工作
position work well in firefox and not working in others
我的页眉中有一个下拉菜单,我希望当单击页眉中的按钮时,下拉菜单会显示在该按钮下方。
那个按钮的位置是绝对的,我用 jquery 的位置来得到那个按钮的左边和底部。但这只是在 firefox 中工作。为什么?
这是我的代码:
var search_div_top=($("#search-div").position().top);
var search_div_left=($("#search-div").position().left);
这是我的 css:
#search-div{
width:200px;
height:60px;
/*center:*/
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
}
just firefox return 该元素的左右实数,其他元素return 0. #search-div
的父元素是relative
.
问题是什么?
Chrome 和其他浏览器(不是 Firefox)的问题是:
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
在上面的 CSS 中 div 将显示在其父级的中心,如果您在上面的代码中看到我们有 left:0
和 right:0
和 chrome 查看此代码并获取其中之一并从左或右开始,值为 0。
所以,解决方法是什么:
在jquery中有一个获取元素位置的函数,只需使用下面的代码:
var search_div_top=($("#search-div").offset().top);
var search_div_left=($("#search-div").offset().left);
我的页眉中有一个下拉菜单,我希望当单击页眉中的按钮时,下拉菜单会显示在该按钮下方。
那个按钮的位置是绝对的,我用 jquery 的位置来得到那个按钮的左边和底部。但这只是在 firefox 中工作。为什么?
这是我的代码:
var search_div_top=($("#search-div").position().top);
var search_div_left=($("#search-div").position().left);
这是我的 css:
#search-div{
width:200px;
height:60px;
/*center:*/
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
}
just firefox return 该元素的左右实数,其他元素return 0. #search-div
的父元素是relative
.
问题是什么?
Chrome 和其他浏览器(不是 Firefox)的问题是:
position:absolute;
left:0;
right:0;
top:0;
bottom:0;
margin:auto;
在上面的 CSS 中 div 将显示在其父级的中心,如果您在上面的代码中看到我们有 left:0
和 right:0
和 chrome 查看此代码并获取其中之一并从左或右开始,值为 0。
所以,解决方法是什么:
在jquery中有一个获取元素位置的函数,只需使用下面的代码:
var search_div_top=($("#search-div").offset().top);
var search_div_left=($("#search-div").offset().left);