HTML布局居中 [英] HTML layout centered

查看:139
本文介绍了HTML布局居中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个HTML布局,我创建了一些元素,并给他们一个边框等在我的CSS。我试图让主要的包装中心,所以在这个元素内的所有内容也居中。

I am trying to create a HTML layout and I have created a number of elements and given them a border etc in my CSS. I am trying to have the main 'Wrapper' centered so everything that goes inside this element are also centered.

我已经尝试过一切,边距,对齐,绝对等等工作中。我的住宿位于我的页面的左上角。

I have tried everything, margin, align, absolute etc and nothing is working. My stays situated in the top left corner of my page.

这是我的索引页面,其中的元素是:

This is my index page where the elements are:

<!--#include file ="inc.heads.asp"-->

<html>

<head>
</head>

<body>
 <div id ="divWrapper">
  <div id ="divHeader">
   <img src="Images/title.png">
   <br>
   <div id ="divNavBar">
    <br>
     <div id ="divContent">
     </div>
   </div>
  </div>
 </div>
</body>

</html>

这是我的CSS:

body {
 background-color: #300;
}

#divWrapper {
 margin: 0 auto;
 width: 800px;
}

#divHeader {
 width: 500px;
 border-style: inset;
 border-color: #COCOCO;
 background-color: #707070;
 padding: 5px;
}

#divNavBar {
width: 500px;
border-style: inset;
border-color: #COCOCO;
background-color: #707070;
padding: 5px;
}

#divContent {
 float: left;
 width: 500px;
 border-style: inset;
 border-color: #COCOCO;
 background-color: #707070;
 padding: 5px;
}

如果有人可能阐明为什么我没有尝试工作以及可能的解决方案。

If someone could possibly shed some light on why none of the things I have tried work and what a possible solution could be.

谢谢!

推荐答案

严重的是,所有这些包装的点是什么?只要这样做:

Seriously what is the point of all those wrappers? Just do this:

body {width: 800px; margin: 0 auto; }

这篇关于HTML布局居中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆