开发者

How do I center my webpage?

How do I center my webpage?

Something like this, notice the borders on both sides of the text?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>Sepia!</title>

  <link rel="stylesheet" href="mystyle.css">
  <style type="text/css">


  body {
    padding-top: 14em;
    padding-left: 30em;
    text-align: center;
    font-family: Arial ;
    color: #414189;
    background-color: #0f0f0f}
 ul.navbar {
    list-style-type: none;
    padding: 0;
    margin: 0;
    position: absolute;
    top: 1em;
    left: 10em;
    width: 9em }
 h1 {
    font-family: Arial }
 ul.navbar li {
    background: #0f0f0f;
    padding: 0.4em;
   }
  ul.navbar a {
    text-decoration: none }
  a:link {
    color: #0f0f0f}
  a:visited {
    color: #0f0f0f}
  address {
    margin-top: 1em;
    padding-top: 1em }


  </style>


</head>

<body>

<!-- Site navigation menu -->
<ul class="navbar">
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button开发者_Python百科_demo5.png" 

alt="Button 1" /></a>
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png" 

alt="Button 1" /></a>
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png" 

alt="Button 1" /></a>
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png" 

alt="Button 1" /></a>
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png" 

alt="Button 1" /></a>
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png" 

alt="Button 1" /></a>
</ul>

<!-- Main content -->

<p>para 1

<p>para 2




<address>Date<br>
  Sepia </address>

</body>
</html>

EDIT:

Tried it and it doesn't seem to be working, what did I do wrong? The text is centered but not the images.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
  <title>Sepia!</title>

  <link rel="stylesheet" href="mystyle.css">
  <style type="text/css">


  body {
    padding-top: 14em;
    padding-left: 20em;
    font-family: Arial ;
    color: #414189;
    background-color: white}

   wrap {
   width: 900px;             
   margin: 0 auto;           
   background-color: #0f0f0f}

 ul.navbar {
    list-style-type: none;
    padding: 0;
    margin: 0;
    position: Absolute;
    top: 1em;
    left: 1em;
    width: 9em }
 h1 {
    font-family: Arial }
 ul.navbar li {
    background: #0f0f0f;
    padding: 0.4em;
   }
  ul.navbar a {
    text-decoration: none }
  a:link {
    color: #0f0f0f}
  a:visited {
    color: #0f0f0f}
  address {
    margin-top: 1em;
    padding-top: 1em }


  </style>


</head>

<body>
<div id="wrap">
<!-- Site navigation menu -->
<ul class="navbar">
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo5.png" alt="Button 1" /></a>
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png" alt="Button 1" /></a>
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png" alt="Button 1" /></a>
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png" alt="Button 1" /></a>
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png" alt="Button 1" /></a>
  <li><img src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png" alt="Button 1" /></a>
</ul>

<!-- Main content -->

<p>para 1

<p>para 2




<address>Date<br>
  Sepia </address>
</div>
</body>
</html>


You can do this by wrapping all your site's content in a wrapping element. You then set the width of this wrap element and center it using the following CSS:

body {
   background-color: #ddd;   /* the colour on the edges of the screen */
}

#wrap {
   width: 700px;             /* Set wrapper's width */
   margin: 0 auto;           /* Center the wrapper in the window */
   background-color: #fff;   /* the colour of the wrapper */
}

The HTML will look like the following:

<body>
    <div id="wrap">
        all your site's content
    </div>
</body>


try the following code (based of ur edited code). I have corrected some of you html 'grammar' and edited the ul.navbar{} css style. Let me know if there are any error or anythign missing

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>

  <head>
    <title>Sepia!</title>

      <link rel="stylesheet" href="mystyle.css">
      <style type="text/css">
          body
          {
            padding-top:14em;
            padding-left:20em;
            font-family:Arial;
            color:#414189;
            background-color:#FFF;
          }

          wrap
          {
            width:900px;
            background-color:#0f0f0f;
            margin:0 auto;
          }

          ul.navbar
          {
            list-style-type:none;
            float: left;
            top:1em;
            left:1em;
            width:9em;
            margin:0;
            padding:0;
            margin-right: 15px;
          }

          h1
          {
            font-family:Arial;
          }

          ul.navbar
          li
          {
            background:#0f0f0f;
            padding:.4em;
          }

          ul.navbar
          a
          {
            text-decoration:none;
          }

          address
          {
            margin-top:1em;
            padding-top:1em;
          }

          a:link,a:visited
          {
            color:#0f0f0f;
          }
      </style>
  </head>
  <body>
    <div id="wrap">
      <!-- Site navigation menu -->
      <ul class="navbar">
        <li>
          <a>
            <img
            src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo5.png"
            alt="Button 1"
            />
          </a>
        </li>
        <li>
          <a>
            <img
            src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png"
            alt="Button 1"
            />
          </a>
        </li>
        <li>
          <a>
            <img
            src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png"
            alt="Button 1"
            />
          </a>
        </li>
        <li>
          <a>
            <img
            src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png"
            alt="Button 1"
            />
          </a>
        </li>
        <li>
          <a>
            <img
            src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png"
            alt="Button 1"
            />
          </a>
        </li>
        <li>
          <a>
            <img
            src="C:\Users\user\Pictures\Style\SepiaWeb\button_demo4.png"
            alt="Button 1"
            />
          </a>
        </li>
      </ul>

      <!-- Main content -->
      <p>para 1</p>        
      <p>para 2</p>
      <address>Date<br>Sepia </address>

  </div>
  </body>
</html>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜