HTML5 <div>位于<body>中

noo*_*ber 4 html5

有没有办法将div置于体内,居中,给定的左右边距等于x和上下边距,等于y?除了div(及其子代)之外,文档中没有任何内容.

UPDATE.我想要以下内容:

在此输入图像描述

此外,我很高兴有一个更常见的解决方案,当x1!= x2,y1!= y2时(虽然我的特殊情况解决方案x1 == x2,y1 = = y2).

小智 8

更好的解决方案(?):将div的margin-left和margin-right设置为"auto"


igo*_*gor 5

您可以使用固定定位。但是,它在 IE6 中不起作用。

<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='de' lang='de'>
    <head>
        <meta charset='utf-8' />
        <title>Test</title>
        <style>
            #bla {
                position: fixed;
                top: 30px;
                left: 60px;
                right: 60px;
                bottom: 30px;
                background: yellow;
            }
        </style>
    </head>
    <body>
        <div id='blah'>
        </div>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

看到它在行动:http : //obda.net/stackoverflow/position-fixed.html