HTML5< div>居中于< body> [英] HTML5 <div> centered inside <body>
问题描述
有没有办法将div置于体内,居中,给定的左右边距等于x和上下边距,等于y?除了div(及其子代)之外,文档中没有任何内容。
Is there a way to place a div inside body, centered, with given left-right margins equal to x and top-bottom margins, equal to y? Nothing except of the div (and its children) is presented in the document.
更新。我想要以下内容:
UPDATE. I want the following:
此外,我很高兴有一个更常见的解决方案,当x1!= x2,y1!= y2时(虽然我的特定情况的解决方案) x1 == x2,y1 == y2表示赞赏。
Also, I'd be glad to have a more common solution for the case, when x1 != x2, y1 != y2 (though a solution for my particular case x1==x2, y1==y2 is appreciated).
推荐答案
您可以使用固定定位。但它在IE6中不起作用。
You can use fixed positioning. It won’t work in IE6, though.
<!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>
查看实际操作: http://obda.net/stackoverflow/position-fixed.html
这篇关于HTML5< div>居中于< body>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!