简体   繁体   English

在窗口上调整HTML元素的大小

[英]resize an html element on window resize

I found a similar question a few days ago, and I've been trying to implement one of the suggestions since then without an success. 几天前,我发现了一个类似的问题,从那时起,我一直在尝试实施其中的一项建议,但没有成功。 Any I have an ASPx page, not the master, that has two tables stacked one on top of the other. 我有一个ASPx页面,而不是master页面,其中有两个表,一个表堆叠在另一个表之上。 I've got the top formatted just the way I want. 我已经按照我想要的方式格式化了最高级的格式。 However, the bottom on I want to have it fit within the window, or better yet, show a vertical scrollbar. 但是,我要使其底部适合窗口,或者更好的是显示垂直滚动条。

I've wrapped the bottom table in a div with overflow-style: auto; 我已经用溢出样式将底部表格包装在div中:auto; in the CSS file. 在CSS文件中。 Then I'm using the following script in the page to manage the resizing: 然后,我在页面中使用以下脚本来管理大小调整:

    $(function () {
        $('.tblContent table').css({ 'height': (($(window).height()) - 50) + 'px' });

        $(window).resize(function () {
            $('.tblContent table').css({ 'height': (($(window).height()) - 50) + 'px' });
        });
    });

My div looks like: 我的股利看起来像:

<div class="tblContent">

The CSS file contains: CSS文件包含:

.tblContent 
{
    overflow-style: auto;
}

I'm not a master of css, but make sure to give your table a specific height to cause overflow to occur. 我不是CSS的高手,但是请确保为您的桌子指定特定的高度,以免发生溢出。

.tblContent 
{
    overflow: auto;
    height : 400px;
    display : block;
}

Why display : block;? 为什么显示:block ;? Because I suck at css and I use that for almost everything. 因为我很讨厌CSS,所以几乎所有东西都用它。 Also, I use overflow: auto. 另外,我使用溢出:自动。 I'm not sure what overflow-style is, although it could be correct. 我不确定是哪种溢出方式,尽管它可能是正确的。

Also, since we both are terrible at css, here is a css reference link. 另外,由于我们俩在CSS方面都很糟糕,因此这里有一个CSS参考链接。

http://www.w3schools.com/cssref/pr_pos_overflow.asp http://www.w3schools.com/cssref/pr_pos_overflow.asp

for the bottom div containing the table (assuming you want it as 50% of the screen. you can obviously adjust that.): 包含表格的底部div(假设您希望将其作为屏幕的50%。您显然可以对其进行调整。):

overflow:auto;
height:50%;
width:100%;

for the table itself: 对于表格本身:

width:100%;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM