div固定宽或者高,另一个div填充剩余空间

在web开发中会经常看到这样的布局,黑色部分高度为100%,宽度是个固定值,灰色部分高度是固定值,宽度是除去黑色部分的剩余宽度,白色的部分的宽高则分别是除去黑色部分的宽度、除去灰色部分的高度。通常,黑色部分最容易确定。灰色和白色部分就会因为对html的布局不够熟悉而不知道怎么办。我们知道html有个position:fixed,这样是可以指定top,left,right,bottom的值的。正好可以利用这个实现以下布局(设置三个部分的position属性为fixed,黑色部分的left,top为0px,width 215px,height 100%,灰色部分top 0px,left为黑色部分的宽度215px,白色部分的left也一样215px;设置灰色和白色部分的right为0px,灰色高度45px,白色的top为黑色的高度,bottom为0px)

代码如下:

<HTML lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>标签配置</title>
<style type="text/css">

body {
	margin: 0px 0px 0px 0px;
	width: 100%;
	height: 100%;
}
.my-header {
	width: 100%;
	height: 45px;
	margin-top:0px;
	background-color: rgb(244,244,244);
	color: gray;
}
.my-maincontent {
	width: 100%;
	height: 100%;
	margin-top:0px;
}

.my-left-bar {
	width: 215px;
	height:100%;
	position:fixed;
	left:0px;
	background-color: rgb(51, 54, 78);
}

.my-right-content {
	height: 100%;
	position:fixed;
	left:215px;
	top:0px;
	right:0px;
	min-width:215px;
	margin-top:0px;
}

.my-laft-menu {
	color: white;
	height: 100%;
}

.my-bread {
	border-bottom: 1px dotted gray;
	padding-bottom:10px;
	margin-top:10px;
	width: 100%;
	color:gray;
}
.my-bread span{
	padding:6px;
}
.my-bread .active{
	color:rgb(120,120,220);
}
.my-bread .active:hover{
cursor: pointer;
}
.my-main-content{
	margin-left:10px;
	margin-right:10px;
}
.top-menu-item{
	height:100%;
	line-height:45px;
	margin-left:10px;
	display:inline-block;
}
</style>
</head>
<body>
	<div class="my-maincontent">
		<div class="my-left-bar">
			<div class="my-laft-menu">
			</div>
		</div>
		<div class="my-right-content">
			<div class="my-header">
				<div>
					<span class="top-menu-item">一些菜单</span>
				</div>
			</div>
			<div class="my-main-content">
				<div>

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

 

转载于:https://my.oschina.net/marner/blog/1930604

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值