0

how can i set div position at the center of the page with size, for example, 80%/80%.

UPD: margin: 0 auto; works, but only for horizontal alignment. And i also need vertical.

Max Frai
  • 57,874
  • 75
  • 193
  • 301

3 Answers3

2

This page talks about some different ways to achieve vertical centering using css. I've used method 2 before with success but I consider all of these a hack at best.

smack0007
  • 10,566
  • 7
  • 40
  • 47
1

Set a fixed width and auto-margins.

<style type="text/css">
#center {
  width:300px;
  margin-left:auto;
  margin-right:auto;
}
</style>

<body>
<div id="center"></div>
</body>
timdev
  • 60,131
  • 6
  • 78
  • 90
0

This does what you want, but it is not pretty.

<div style="margin: 0 auto;width:80%;height:80%;">
This will probably not work for you however because you did not provide code
</div>