html和css实现 div 切割 并使多个div上下左右排列

首先看我的div布局:
在这里插入图片描述图片有6个div有序排列,位置上下左右不一。
方法1:最简单的做法是设置每个div的width:px;height:px;
比如:
width:1200px;
height:800px;
但是这种方法在不同尺寸的电脑上就无法完全显示div或者div不能充满整个页面。
方法2:设置div的width:
%
;height:
%;
**
比如:
width:20%;
height:60%;

这种方法无论对于不同的电脑尺寸都能全屏显示,本文就选用这种方法。

  1. step1:

建立HTML,添加代码如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My First Web Demo!</title>
<style type="text/css" media="all">@import "css/master.css";</style>
<!--这是让浏览器知道你是使用 CSS1 样式规则。-->
</head>

<body>
<div id="page-container"> 
<div id="main-nav">main-nav
</div>
<div id="multi">
<div id="content">content
</div> 
<div id="footer">
<div id="desk"> desk </div> 
<div id="block"> block</div>
<div id="shelf"> shelf
</div>
</div>
</div>
<div id="sidebar-a">sidebar-A</div>
</div>
</body>
</html>
  1. step2:

建立CSS文件,添加代码如下:

#page-container 
{
	//clear:both;
	overflow: hidden;
width: 100%;
height:100%;
position: relative;
margin: auto;
<!--是左右自适应两边距离一样--居中,-->
>
margin: auto;
background: red;
	text-align: center;
}

html,body 
{
<!--盒子和浏览器的顶端有空隙。由于浏览器的默认的填充和边界造成的。消除空隙-->
margin: auto;
height:100%;
width:100%;
font-family:Sans-serif;
font-size: 16px;
color: #666666;
background: #ffffff;

}
<!--加入类,可以使页面上任意属于hidden类的元素(element)不显示-->
.hidden {display: none;}

#main-nav 
{
background: khaki;
/*position:absolute;会导致main-nav高度不符*/
height:20%;
width:100%;
border-style: dotted;/*点线*/
overflow: hidden;
}

#multi
{
background: black;
height:60%;
width:100%;
float:auto;
font-family: "黑体";
text-decoration: underline; 
}

#content 
{
background:cyan ;
clear: both;
height:100%;
width:20%;
float:left;
font-family: "黑体";
text-decoration: underline; 
border-style:none;
}

#footer 
{
background: green;
width:80%;
	height:100%;
float:right;
} 


#desk
{
clear: both;
margin:auto;
background: pink;
width:100%;
height:20%;
} 
#shelf
{
background: yellow;
float:left;
width:60%;
height:80%;
//border-style:solid;
} 

#block
{
clear: both;
background: lavender ;
float:right;
width:40%;
height:80%;
//border-style:solid;
} 


#sidebar-a 
{
clear:both;
background: tomato;
height:20%;
text-decoration: underline; 
font-family: "华文新魏";
border-style:dashed; /*虚线*/
}
  • 5
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值