[英]Remove Scrollbars, expand div based on Screensize
I have a web page that uses ZURB Foundation. 我有一个使用ZURB Foundation的网页。 Thanks to the responsive design, the page collapses on mobile without needing a separate mobile page redirect.
由于采用了响应式设计,因此页面可以在移动设备上折叠,而无需单独的移动设备页面重定向。 One issue however, is that I have scrollbars that are great on computers, but stack on top of each other for mobile, making reaching the bottom of the page a pain.
但是,一个问题是,我有一些滚动条,它们在计算机上非常有用,但它们相互堆叠以用于移动设备,这使到达页面底部变得很痛苦。
How can I (using CSS and Javascript) make it so that when the screen size is a mobile resolution that the scrollbars disappear, but the divs actually expand when this occurs? 如何(使用CSS和Javascript)做到这一点,以便在屏幕大小为移动分辨率时滚动条消失,而div实际上在发生这种情况时扩展? (When you :hide the overflow it simply hides the overflow, instead of expanding the div).
(当您隐藏溢出时,它只是隐藏了溢出,而不是扩展div)。 Here is an example of what I have:
这是我所拥有的一个例子:
<div class="large-4 columns" data-equalizer-watch id="col3" style="font-weight:bold; padding-bottom:20px; max-height:700px; overflow-y: scroll;">
<h4 style="font-weight:bold; color:white; font-size:x-large; margin-bottom:10px;margin-top:10px;">
<a style="color:white;" target="_blank" href="mylink.com">EVENTS</a></h4>
<div id="events"></div><!-- populated via javascript -->
</div>
if($( window ).width() <= 1025){
alert("mobile screen!");
$('#col2').css({'overflow' : '', 'overflow-y' : ''});
$('#col3').css({'overflow' : '', 'overflow-y' : ''});
}
You can use @media query to set a specific css depending on the resolution of the screen directly from css. 您可以使用@media查询直接根据CSS的屏幕分辨率来设置特定的CSS。
Here is an example: 这是一个例子:
CSS: CSS:
@media all and (max-width: 1025px) {
#target{
height:100%; // will make the div expand as much as needed with no scrollbar
}
}
jsfiddle example: http://jsfiddle.net/r101sjfe/ jsfiddle示例: http : //jsfiddle.net/r101sjfe/
Use this media query to a) remove the max-height restriction from the div to allow it to expand and b) remove the scroll bars. 使用此媒体查询可以:a)删除div的最大高度限制以使其展开,以及b)删除滚动条。 But first put your CSS into a stylesheet, or at least into
<style> </style>
tags, so you don't need to use !important to override your inline styles. 但是首先将CSS放入样式表中,或至少放入
<style> </style>
标记中,因此您无需使用!important即可覆盖内联样式。 You then have: 然后,您将拥有:
#col3 {
font-weight:bold;
padding-bottom:20px;
max-height:700px;
overflow-y: scroll;
}
@media all and (max-width: 480px) {
#col3 {
max-height: none;
overflow-y: auto;
}
}
The 480px breakpoint captures a majority of mobiles but not all of them as there is a huge variation in screen sizes - use a higher max-width if you prefer. 480像素的断点可捕获大多数移动设备,但并非全部移动设备,因为屏幕尺寸差异很大-如果您愿意,可以使用更大的最大宽度。 I hope this gives you what you want.
我希望这能给您您想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.