-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
  • 963,270
  • 265
  • 3,804
  • 3,187
felwithe
  • 2,545
  • 2
  • 22
  • 37

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
  • 59,058
  • 16
  • 59
  • 114