html - 使用 DIV 格式化页面布局

标签 html css

我知道有很多关于使用 DIV 和 CSS 布局页面的问题和答案,但没有一个能帮助我接近我正在寻找的布局。

我正在努力改掉使用表格布局页面的习惯(我很少进行页面布局,旧习惯很难改掉)。

我正在寻找的布局(在黑页上)是:

enter image description here

如果屏幕显示的宽度超过 800 像素,我希望它保留在页面中央

我目前的 HTML 是:

<body>
   <form id="form1" runat="server">
      <div id="header">Header</div>
      <div id="outerleftcolumn">Left Column</div>
      <div id="leftcolumn">Left Column</div>
      <div id="content">Content</div>
      <div id="outerrightcolumn">Left Column</div>
      <div id="footer">Footer</div>
   </form>
</body>

我目前拥有的 CSS:

body {
margin: 0px;
padding: 0px;
background-color:black;
}

#header {
background: #438a48;
width: 770px;
height:50px;
}
#outerleftcolumn {
background-image:url(/Templates/Red/Images/LeftBoarder.jpg);
float: left;
width: 15px;
height: 700px;
}
#leftcolumn {
background: #2675a8;
float: left;
width: 150px;
height: 700px;
}
#outerrightcolumn
{
background-image: url(/Templates/Red/Images/RightBoarder.jpg);
float: right;
width: 15px;
height: 700px;
}
#content {
background: #ff6a00;
float: left;
width: 635px;
height: 700px;
}
#footer {
background: #df781c;
clear: both;
width: 800px;
 }

我一直在阅读一篇文章或帖子,并认为我知道我只需要更改一个设置就可以做什么,而整个事情就变得疯狂啦啦啦。我可以在心跳中使用表格来实现这一点,但正如我所说,我正在努力(但失败了)改掉我的坏习惯。两个外部 div 中的图像只是带有渐变的 jpg。

任何指针将不胜感激。

最佳答案

body {
	margin: 0px;
	padding: 0px;
	background-color:#000;
}
#outerleftcolumn {
	float: left;
	width: 15px;
	height: 700px;
	background-color: red;
}
#outerrightcolumn
{
	background-image: url(/Templates/Red/Images/RightBoarder.jpg);
	float: right;
	width: 15px;
	height: 700px;
	background-color: red;
}
#centercolumn{
	overflow: hidden;
}
form{
	display: block;
	margin: auto;
	width: 800px;
	background-color: #000;
}
#header {
	background: #438a48;
	width: 770px;
	height:50px;
}

#leftcolumn {
	background: #2675a8;
	float: left;
	width: 150px;
	height: 620px;
}
#content {
	background: #fff;
	float: left;
	width: 620px;
	height: 620px;
}
#anotherheader{
	float: left;
	width: 100%;
	height: 50px;
	background-color: yellow;
}
#footer {
	background: #df781c;
	height: 30px;
	width: 800px;
	float: left;
 }
<body>
   <form id="form1" runat="server">
   		<div id="outerleftcolumn">Left Column</div>
   		<div id="outerrightcolumn">Left Column</div>
   		<div id="centercolumn">
   			<div id="header">Header</div>
   			<div id="leftcolumn">Left Column</div>
   			<div id="content">
   				<div id="anotherheader">

   				</div>
   			</div>
   			<div id="footer">Footer</div>
   		</div>
   </form>
</body>

关于html - 使用 DIV 格式化页面布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26652347/

相关文章:

javascript - 确定 GPS 状态 javascript

html - 我的页面没有响应并且在移动 View 中看起来很奇怪

javascript - Chrome 扩展程序在单击按钮时弹出一个新窗口

html - 如何根据屏幕高度调整div

javascript - 刷新页面时标题外观不起作用

html - 带有 colspan 的 TD 中固定宽度的 DIV

javascript - 用 Flexbox 将内联 ul 并排包装起来

javascript - 在输入标签上使用 keyup 事件的 JS 搜索

css - 如何使 jQuery 对话框宽度适应移动浏览器?

css - 名词元素 CSS 包装器?