繁体   English   中英

动态div底部

[英]Dynamic div bottom

我有三个div:头,脚和文本框。 头和脚的div是固定位置,而第三个div是部分固定的(上边距)。

我的问题是:如何更改文本框的div底部以固定不同的显示器尺寸? 我不能使用100%的高度,因为它悬挂在div上。 在此主页中,我不使用滚动条,因为背景正更改图像文件。 我想以某种方式使其边缘底部与显示器底部保持一定距离。


<html>
<head>
<title>Div bottom</title>
<style>
.head{
    position:absolute;
    clear:both;
    top:0px;
    right:0px;
    float:right;
    width:100%;
    height:80px;
    background-color:grey;
}
.foot {
    position:fixed;
    clear:both;
    height:35px;
    right:0px;
    float:right;
    width:100%;
    background-color:grey;
    bottom:0px;
}
.textbox {     
    overflow: hidden;
    position: relative;
    padding:20px;
    border: 1px solid gray; 
    background-color:red;
    z-index:0;
    text-align:justify;
    color:black;
    line-height: 2em;
    border-radius: 3px;
    margin-top:100px;
    width:910px;
    margin-left: auto; 
    margin-right:auto;
}
</style>
</head>

<body>
<div class="head">HEAD</div>

<div class="textbox">?</div>

<div class="foot">FOOT</div>
</body>
</html>

您可以使用javascript完成此操作..将以下脚本添加到您的头上:

<script type="text/javascript">
window.onload=resize_height;

function resize_height(){
    var height=0;
    var divs=document.getElementsByTagName('div');
    if(self.innerHeight){
        height=self.innerHeight;
    }else if(document.documentElement && document.documentElement.clientWidth){
        height=document.documentElement.clientHeight;
    }else if(document.body){
        height=document.body.clientHeight;
    }
    divs[1].style.height=(parseInt(height)-200)+'px';
}

</script>

200来自高度,边距和边距,您可以通过获取其他div的高度/边距并将其偏移以实现所需的值来动态生成200。

编辑:

另外,对于文本框,删除margin-top:100px; 并替换为top:100px; ....

.textbox {
    overflow: hidden;
    position: relative;
    top:100px;
    padding:20px;
    border: 1px solid gray;
    background-color:red;
    z-index:0;
    text-align:justify;
    color:black;
    line-height: 2em;
    border-radius: 3px;
    /*margin-top:100px;*/
    width:910px;
    margin-left: auto;
    margin-right:auto;
}

您不必为此使用脚本, 这里是“页眉内容页脚”布局的纯CSS解决方案。

区域之间的边距是可选的,垂直和水平居中也是如此。 一切都完全灵敏。

HTML:

<div class="Container">
    <div class="Header">
    </div>
    <div class="HeightTaker">
        <div class="Wrapper Container Inverse">
            <div>
                <div class="Footer">
                </div>
            </div>
            <div class="HeightTaker">
                <div class="Wrapper Content">
                    <div class="Centered">
                    </div>
                </div>
            </div>
        </div>
    </div>

CSS:

*
{
    margin: 0;
    padding: 0;
}
html, body, .Container
{
    height: 100%;
}
    .Container:before
    {
        content: '';
        height: 100%;
        float: left;
    }
.HeightTaker
{
    position: relative;
    z-index: 1;
}
    .HeightTaker:after
    {
        content: '';
        clear: both;
        display: block;
    }
.Wrapper
{
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: auto;
}
.Inverse, .Inverse > *
{
    -moz-transform: rotateX(180deg);
    -ms-transform: rotateX(180deg);
    -o-transform: rotate(180deg);
    -webkit-transform: rotateX(180deg);
    transform: rotateX(180deg);
}

/*For Centering only*/
    .Content:before
    {    
        content: '';
        display: inline-block;
        height: 100%;
        vertical-align: middle;
        margin-left: -5px;
    }
    .Centered
    {
        display: inline-block;
        vertical-align: middle;
    }


/*For demonstration only*/
p
{    
    font-size: 1.3em;
}

.Important
{
    font-weight: bolder;
    color: white;
}

body > .Container
{
    padding: 0 5px;
    text-align: center;
}

.Header, .Footer
{
    margin-bottom: 5px;
    padding: 5px 0;
}
.Header
{
    background-color: #bf5b5b;
}
.Content
{
    background-color: #90adc1;
}
.Footer
{
    background-color: #b5a8b7;
}

暂无
暂无

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

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