本文介绍了CSS 高度 100% 仍然溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有一个这样的代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><style type="text/css">身体 {背景:#000;}#标题{浮动:右;宽度:800px;}#顶栏{位置:绝对;顶部:0;左:0;宽度:100%;高度:30px;}#容器盒{边距:0px 自动;边框:1px纯黑色;宽度:950px;边距顶部:40px;高度:550px;}#图像框{边框:3px 纯黑色;位置:绝对;向左飘浮;宽度:120px;高度:120px;z-索引:1000;背景:#000099;}#内盒{z-索引:-100;边距:0px 自动;边框:1px 实心 #737373;宽度:900px;边距顶部:50px;高度:100%;}#内左{向左飘浮;右边框:1px 实心 #737373;宽度:250px;高度:100%;文字对齐:底部;}#右内{浮动:右;宽度:649px;颜色:#FFFFFF;}#右上{向左飘浮;宽度:649px;高度:375px;边框底部:1px 实心 #737373;}#right-btm{向左飘浮;填充顶部:5px;宽度:649px;高度:150px;}#页脚{颜色:#c3c3c3;}#footer #footer_left{向左飘浮;宽度:200px;字体大小:9px;边距顶部:5px;左边距:30px;文本对齐:左;}#footer #footer_right{浮动:右;宽度:500px;字体大小:14px;边距右:30px;边距顶部:5px;文本对齐:右;}#footer #footer_right .linkage{浮动:右;边距右:20px;}#footer #footer_right .linkage a{颜色:#c3c3c3;文字装饰:无;}</风格><div id="标题"><div id="topbar"></div>

<div id="container-box"><div id="图像框"></div><div id="inside-box"><div id="inside-left"><table width="100%" cellspacing="15px" height="100%"><tbody><tr valign="bottom"><td><div class="元素"></div><div class="元素"></div></td></tr></tbody></table>

<div id="inside-right">德国内部边界是 1949 年至 1990 年间德意志民主共和国(东德)和德意志联邦共和国(西德)之间的边界.不包括相似但物理上分开的边界柏林墙,边界长 1,381 公里(858 英里),从波罗的海一直延伸到捷克斯洛伐克.它于 1945 年 7 月 1 日正式成立,作为德国西部和苏联占领区之间的边界.在东部,它是世界上防御工事最严的边境之一,由一连串高高的金属围栏和墙壁、带刺铁丝网、警报器、战壕、瞭望塔、自动诱杀装置和雷区界定.边界是温斯顿·丘吉尔(Winston Churchill)比喻冷战期间将苏联和西方集团分开的铁幕的物理表现.这些防御工事由东德于 1952 年至 1980 年代后期分阶段建造,旨在阻止东德公民大规模移民到西方.它对双方造成了广泛的经济和社会混乱.1989年11月9日,东德政府宣布开放柏林墙和内德边界.德国内部边界直到 1990 年 7 月 1 日才被完全放弃,距其成立整整 45 年,距离德国统一正式结束德国分裂仅三个月.今天,德国内部边界的防御工事几乎没有留下什么.德国内部边界是 1949 年至 1990 年间德意志民主共和国(东德)和德意志联邦共和国(西德)之间的边界.不包括类似但物理上分开的柏林墙,边界为 1,381 公里(858 英里)从波罗的海一直跑到捷克斯洛伐克.它于 1945 年 7 月 1 日正式成立,作为德国西部和苏联占领区之间的边界.在东部,它是世界上防御工事最严的边境之一,由一连串高高的金属围栏和墙壁、带刺铁丝网、警报器、战壕、瞭望塔、自动诱杀装置和雷区界定.边界是温斯顿·丘吉尔(Winston Churchill)比喻冷战期间将苏联和西方集团分开的铁幕的物理表现.这些防御工事由东德于 1952 年至 1980 年代后期分阶段建造,旨在阻止东德公民大规模移民到西方.</div>

</html>

输出是这样的.

目前,内容在框内,因为它尚未到达.但是当内容超过高度时.它会是这样的.因为我设置了固定高度.

请看这张图片

替代文字 http://img5.imageshack.us/img5/9440/outputcss2.png

但是当我将所有高度更改为 100% 高度时,它不起作用.输出变成这样

替代文字 http://img200.imageshack.us/img200/3120/outputcss3.png

谁能帮我解决一下?非常感谢.

此致,

解决方案

我相信您的问题与以下事实有关,即 inside-left 和 inside-right 都是包含 div 中的浮动元素.如果您将以下内容添加到样式表中:

#inside-bottom{清除:两者;}

然后在您的内部右侧 div 定义下方添加以下内容:

<div id="inside-bottom"></div>

你会得到更好的结果.

Currently, I have a code like this

<!DOCTYPE HTML PUBLIC "-// W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
body {
background:#000;
}

#header{
    float:right;
    width:800px;
}

#topbar {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 30px;
}

#container-box{
    margin:0px auto;
    border:1px solid black;
    width:950px;
    margin-top:40px;
    height:550px;
}

#image-box{
    border:3px solid Black;
    position:absolute;
    float:left;
    width:120px;
    height:120px;
    z-index:1000;
    background:#000099;
}

#inside-box{
    z-index:-100;
    margin:0px auto;
    border:1px solid #737373;
    width:900px;
    margin-top:50px;
    height:100%;
}

#inside-left{
    float:left;
    border-right:1px solid #737373;
    width:250px;
    height:100%;
    text-align:bottom;
}

#inside-right{
    float:right;
    width:649px;
    color:#FFFFFF;
}

#right-top{
    float:left;
    width:649px;
    height:375px;
    border-bottom:1px solid #737373;
}

#right-btm{
    float:left;
    padding-top:5px;
    width:649px;
    height:150px;
}

#footer{
    color:#c3c3c3;
}
#footer #footer_left{
    float:left;
    width:200px;
    font-size:9px;
    margin-top:5px;
    margin-left:30px;
    text-align:left;
}

#footer #footer_right{
    float:right;
    width:500px;
    font-size:14px;
    margin-right:30px;
    margin-top:5px;
    text-align:right;
}
#footer #footer_right .linkage{
    float:right;
    margin-right:20px;
}


#footer #footer_right .linkage a{
    color:#c3c3c3;
    text-decoration:none;
}

</style>
</head>
<div id="header">
<div id="topbar"></div>
</div>

<div id="container-box">
    <div id="image-box"></div>
    <div id="inside-box">
        <div id="inside-left">
            <table width="100%" cellspacing="15px" height="100%">
                <tbody><tr valign="bottom">
                    <td>
                                                    <div class="elements"></div>
                                                <div class="elements"></div>
                    </td>
                </tr>
            </tbody></table>
        </div>
        <div id="inside-right">The inner German border was the frontier between the German Democratic Republic (East Germany) and the Federal Republic of Germany (West Germany) from 1949 to 1990. Not including the similar but physically separate Berlin Wall, the border was 1,381 kilometres (858 mi) long and ran from the Baltic Sea to Czechoslovakia. It was formally established on 1 July 1945 as the boundary between the Western and Soviet occupation zones of Germany. On the Eastern side, it was made one of the world's most heavily fortified frontiers, defined by a continuous line of high metal fences and walls, barbed wire, alarms, trenches, watchtowers, automatic booby-traps and minefields. The border was a physical manifestation of Winston Churchill's metaphor of an Iron Curtain separating the Soviet and Western blocs during the Cold War. Built by East Germany in phases from 1952 to the late 1980s, the fortifications were constructed to stop the large-scale emigration of East German citizens to the West. It caused widespread economic and social disruption on both sides. On 9 November 1989, the East German government announced the opening of the Berlin Wall and the inner German border. The inner German border was not completely abandoned until 1 July 1990, exactly 45 years to the day since its establishment, and only three months before German reunification formally ended Germany's division. Little remains today of the inner German border's fortifications. The inner German border was the frontier between the German Democratic Republic (East Germany) and the Federal Republic of Germany (West Germany) from 1949 to 1990. Not including the similar but physically separate Berlin Wall, the border was 1,381 kilometres (858 mi) long and ran from the Baltic Sea to Czechoslovakia. It was formally established on 1 July 1945 as the boundary between the Western and Soviet occupation zones of Germany. On the Eastern side, it was made one of the world's most heavily fortified frontiers, defined by a continuous line of high metal fences and walls, barbed wire, alarms, trenches, watchtowers, automatic booby-traps and minefields. The border was a physical manifestation of Winston Churchill's metaphor of an Iron Curtain separating the Soviet and Western blocs during the Cold War. Built by East Germany in phases from 1952 to the late 1980s, the fortifications were constructed to stop the large-scale emigration of East German citizens to the West..</div>
</div>

</div>
</body>
</html>

The output is like this.

Currently, content is inside the box because it's not reach yet. But when content is exceed the height. It is going to be like this. Because i set the fixed height.

Please see this image

alt text http://img5.imageshack.us/img5/9440/outputcss2.png

But when I change all the height as 100% height, it doesn't work. Output is changed like this

alt text http://img200.imageshack.us/img200/3120/outputcss3.png

Can anyone help me to fix it ? Thanks much.

With Regards,

解决方案

I believe your problem has to do with the fact that both inside-left and inside-right are floating elements within the containing div. If you add the following to your style sheet:

#inside-bottom{
    clear:both;
}

And then add the following just below your inside-right div definition:

<div id="inside-bottom"></div>

You will get a much better result.

这篇关于CSS 高度 100% 仍然溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 19:37