html盒子左右边界,html和css实现 div 切割 并使多个div上下左右排列

首先看我的div布局:

34e4ee2d012cd8020fdb5653bbd033de.png图片有6个div有序排列,位置上下左右不一。

方法1:最简单的做法是设置每个div的width:px;height:px;

比如:

width:1200px;

height:800px;

但是这种方法在不同尺寸的电脑上就无法完全显示div或者div不能充满整个页面。

方法2:设置div的width:%;height:%;**

比如:

width:20%;

height:60%;

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

step1:

建立HTML,添加代码如下:

My First Web Demo!

content

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 {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; /*虚线*/

}

  • 0
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值