开发者

Bottom div within td, zero margin

开发者 https://www.devze.com 2023-03-12 11:03 出处:网络
<!DOCTYPE html> <html> <head> <title>MyTitle</title> <style type=\"text/css\">
<!DOCTYPE html>
<html>
<head>
    <title>MyTitle</title>
    <style type="text/css">
        body
        {
            background-image:url('images/my.png');
            /*width:100%;*/
            height:100%;
            background-repeat:no-repeat;
            background-size:100%;
            /*background-position:0,0,0,0px;
            background-position:center;*/
            margin: 0;
            padding: 0;
        }
        html
        {
            height: 100%;
        }
    </style>
</head>
<body>
    <table cellpadding="0" cellspacing="0"
        style="height:100%; width: 100%; border-collapse: collapse; background-color: Red; border-color:Yellow;">
        <tr style="background-color: Green;">
            <td style="background-color: Blue; text-align: center; vertical-align: bottom; padding-bottom:0px;">
                <div style="margin: 0px 0px 0px 0px; background-color:Silver;">
                    <button type="submit">Some text</button开发者_StackOverflow社区>
                    <p style="">Another text</p>
                </div>
            </td>
        </tr>
    </table>
</body>
</html>

FF4. The window is blue, it means td fills the whole window. The div has zero margins, td has zero paddings. Nevertheless, there is a blue rectangle between the div and the bottom edge of the window. How to avoid it? Margin-bottom: -16px; is not an option.

Thank you.


The problem is with the p element - specifically its margin-bottom.

Collapsing margins are the reason this is happening:

  • http://reference.sitepoint.com/css/collapsingmargins
  • http://www.w3.org/TR/CSS2/box.html#collapsing-margins

You can fix it in this instance with overflow: hidden on the div which is the parent of the p.

Your code: http://jsbin.com/enote5

Your code with the fix: http://jsbin.com/enote5/2

(or you could just remove the margin on the p, if you like)

0

精彩评论

暂无评论...
验证码 换一张
取 消