-2

Here is the code. This is as simple as can be. Why won't it center?

.msg {
    width: 600px;
    height: 200px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 100px;
    font-size: 42px;
    font-weight: bold;
}
</style>
</head>
<body>
<div class="msg">This is not centered. Why not?</div>
</body>
</html>
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
felwithe
  • 2,683
  • 2
  • 23
  • 38

1 Answers1

1

It needs to have position: relative;, plus the parent element also needs to have a position setting other than static (which is the default).

Johannes
  • 64,305
  • 18
  • 73
  • 130