admin管理员组文章数量:1317123
I have my main content in the center of the page about 900px wide. on a large screen there is enough space between the right margin of my content and the right side of the browser window that I can display a small 100x100px div in the bottom right corner and it looks good because there is no overlap between that div and the main content. When the screen size is less that div which is relatively positioned overlaps with the bottom right corner of my content. How can I set the display=none of the div if it es within 20px of my content? Thanks
I have my main content in the center of the page about 900px wide. on a large screen there is enough space between the right margin of my content and the right side of the browser window that I can display a small 100x100px div in the bottom right corner and it looks good because there is no overlap between that div and the main content. When the screen size is less that div which is relatively positioned overlaps with the bottom right corner of my content. How can I set the display=none of the div if it es within 20px of my content? Thanks
Share Improve this question asked Aug 2, 2011 at 9:16 user852974user852974 2,28210 gold badges41 silver badges65 bronze badges 1- Can you post a JS Fiddle demo that reproduces your mark-up, so that we can see what you're working with and how to best help you? – David Thomas Commented Aug 2, 2011 at 9:24
2 Answers
Reset to default 10I'd go for a pure CSS solution here. Sounds like a perfect case for media queries
:
#rightdiv {
position: relative;
width: 100px;
height: 100px;
}
@media screen and (max-width: 1000px) {
#rightdiv {
display: none;
}
}
That CSS will only display the #rightdiv
element when the browser window size has at least 1000px width. If it gets smaller, it applies the display: none
property.
Example: http://jsfiddle/7CCtH/
As for media queries are not familiar with IE I suggest you kindly this solution for your problem:
DEMO
code used:
function hideSmall(){
var smallW = $('#small').outerWidth(true);
var winW = $(window).width();
var mainW = $('#main').outerWidth(true);
var calculateW = (winW-mainW)/2;
if ( calculateW <= smallW ){
$('#small').hide();
}
else{
$('#small').show();
}
}
hideSmall();
$(window).resize(function(){
hideSmall();
});
or like THIS
本文标签: javascriptHide a div if it overlaps another divStack Overflow
版权声明:本文标题:javascript - Hide a div if it overlaps another div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742001817a2411167.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论