Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Css 100%宽度网站中的包装DIV_Css_Html - Fatal编程技术网

Css 100%宽度网站中的包装DIV

Css 100%宽度网站中的包装DIV,css,html,Css,Html,我正在创建一个网站,其中页眉,页脚,正文都是100%的页面宽度,但我需要所有的内容都要居中的页面,无论分辨率。我尝试过使用包装器,但是标题和内容只有包装器的100%宽度,而不是页面 不能对div元素执行此操作,除非它具有指定的宽度 对于文本,您可以使用 <div style="text-align: center;">text content</div> 文本内容 这应该适合您: CSS: body { background-color: #e1ddd9; font-s

我正在创建一个网站,其中页眉,页脚,正文都是100%的页面宽度,但我需要所有的内容都要居中的页面,无论分辨率。我尝试过使用包装器,但是标题和内容只有包装器的100%宽度,而不是页面

不能对div元素执行此操作,除非它具有指定的宽度

对于文本,您可以使用

<div style="text-align: center;">text content</div>
文本内容

这应该适合您:

CSS:

body {
background-color: #e1ddd9;
font-size: 12px;
font-family: Verdana, Arial, Helvetica, SunSans-Regular, Sans-Serif;
color:#564b47;
margin: 20px 140px  20px 140px;
text-align: center;
}
#content {
width: 100%;
padding: 0px;
text-align: left;
background-color: #fff;
overflow: auto;
}
HTML:

<body> 
<div id="content"> 
<p><b>center</b><br /><br /> 
This BOX ist centered and adjusts itself to the browser window.<br /> 
The height ajusts itself to the content.<br /> 
</div> 
</body> 

居中

此框居中,并根据浏览器窗口进行调整。
高度根据内容调整。
此示例取自此网站,我不久前发现了此网站,并始终参考此网站以获取简单、干净的css模板:

玩一下这个吧

body    {
  text-align: center;
  position: relative; 
}

#content    {
  width: 100%;
  height: auto;
  position: relative;
  margin-left: auto;
  margin-right: auto;
}
然后在HTML中

<html>
<body>
<div id="header"></div>
<div id="content">
    <!-- place all of your content inside of here  -->
</div>
</body>
</html>

我要冒险出去,猜测背景色/图像是100%宽的,但您希望实际内容居中(固定宽度?)。下面是一个示例代码,它在每个项目上使用内部包装器
div
,以保持内部内容居中。我建议做一些完全不同的事情,可能在
html
body
元素上使用重复的背景,但我不知道你的页面是什么样子

因此..,以下内容可以工作,但会因为额外的标记而警告HTML纯粹主义者:)

您可以查看我编写的这个方法的一个(超级丑陋)示例

CSS:

.wrapper {
   width: 960px; /* fixed width */
   margin: 0 auto; /* center */
}
<div id="header">
   <div class="wrapper">
   <h1>My Title</h1>
   </div>
</div>
<div id="content">
   <div class="wrapper">
   <h2>Sub Title</h2>
   <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
      do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
      Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris 
      nisi ut aliquip ex ea commodo consequat.</p>
   </div>
</div>
<div id="footer">
   <div class="wrapper">
   <p class="credits">Copyright 2009 by Your Company.com, LLC</p>
   </div>
</div>
HTML:

.wrapper {
   width: 960px; /* fixed width */
   margin: 0 auto; /* center */
}
<div id="header">
   <div class="wrapper">
   <h1>My Title</h1>
   </div>
</div>
<div id="content">
   <div class="wrapper">
   <h2>Sub Title</h2>
   <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed 
      do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
      Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris 
      nisi ut aliquip ex ea commodo consequat.</p>
   </div>
</div>
<div id="footer">
   <div class="wrapper">
   <p class="credits">Copyright 2009 by Your Company.com, LLC</p>
   </div>
</div>

我的头衔
副标题
Lorem ipsum dolor sit amet,圣公会精英,sed
临时性的劳动和工作都是不可能的。
但是,我们必须尽可能少地进行实验
从一个普通的消费品中购买

版权所有2009年由贵公司网站有限责任公司提供


@Matt左边的
边距
和右边的
边距
没有任何意义,因为宽度是
100%