-1
<!DOCTYPE html>
<html>
<head>
    <title>My first website</title>
    <meta charset="utf-8">
    <style type="text/css">
    div{
        margin:0 auto;
    }   
    </style>
</head>

<body>
    <div>
    <h1>My First Website</h1>
    <p> Welcome to my webiste! Here are some things I enjoy.</p>
    <ul>
        <li>Web Development</li>
        <li>Chess</li>
        <li>Reading</li>
        <li>Learning</li>
    </ul>
    <h2>Favorite Quotes</h2>
    <blockquote>
        <p>Here is a favorite quote of mine...</p><br>
        <p> ...and another"</p>   
    </blockquote>
    </div>
</body>

why isnt this working? I want to have everything in the div to be at the center of the page, currently it is aligned to the left. Thanks in advance.

frankcrest
  • 107
  • 1
  • 5
  • 12

1 Answers1

1

You need to set fixed width as by default you div is 100% width and it's centered, but you don't see it:

div {
   margin:0 auto;
   width: 900px; /* or 80% */
} 

Example

John Slegers
  • 45,213
  • 22
  • 199
  • 169
Morpheus
  • 8,829
  • 13
  • 51
  • 77