css内外边距样式

外边距样式

1.margin-top

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<link rel="stylesheet" type="text/css" href="1.css"/>
<div id="div1">
<div id="div2"></div>
</div>
</body>
</html>

@charset "utf-8";
/* CSS Document */
#div1
{
	width:300px;
	height:300px;
	border:solid 5px red;
}
#div2
{
	width:30px;
	height:30px;
	border:solid 5px blue;
	margin-top:40px;
}


2.margin-right

 不能用来定义子块与父块的距离,只能定义子块与子块之间的距离。

不是浮动情况下,margin-right没有作用的

3.margin-bottom

 不能用来定义子块与父块的距离,只能定义子块与子块之间的距离

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<link rel="stylesheet" type="text/css" href="1.css"/>
<div id="div1">
<div id="div2"></div>
<div id="div3"></div>
</div>
</body>
</html>

@charset "utf-8";
/* CSS Document */
#div1
{
	width:300px;
	height:300px;
	border:solid 5px red;
}
#div2
{
	width:30px;
	height:30px;
	border:solid 5px blue;
	margin-bottom:100px;
}
#div3
{
	width:40px;
	height:40px;
	border:solid 2px blue;
}


4.margin-left

@charset "utf-8";
/* CSS Document */
#div1
{
	width:300px;
	height:300px;
	border:solid 5px red;
}
#div2
{
	width:30px;
	height:30px;
	border:solid 5px blue;
	margin-left:40px;
}


5.margin


 四个参数:上、右、下、左

 三个参数:上、左右、下

 两个参数  上下、左右

以两个参数的为例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<link rel="stylesheet" type="text/css" href="1.css"/>
<div id="div1">
<div id="div2"></div>
</div>
</body>
</html>


@charset "utf-8";
/* CSS Document */
#div1
{
	width:300px;
	height:300px;
	border:solid 5px red;
}
#div2
{
	width:30px;
	height:30px;
	border:solid 5px blue;
	margin:200px 50px;
}



内边距样式

1.padding-top


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<link rel="stylesheet" type="text/css" href="1.css"/>
<div id="div1">
11111111111111111111111111111
</div>
</body>
</html>

@charset "utf-8";
/* CSS Document */
#div1
{
	width:300px;
	height:300px;
	border:solid 5px red;
	padding-top:100px;
}

2.padding-right


@charset "utf-8";
/* CSS Document */
#div1
{
	width:300px;
	height:300px;
	border:solid 5px red;
	padding-right:200px;
}

这个相比top的宽度是不是变宽了 仔细对比一下

3.padding-bottom


@charset "utf-8";
/* CSS Document */
#div1
{
	width:300px;
	height:300px;
	border:solid 5px red;
	padding-bottom:10px;
}

不截图了 自己改变padding-bottom的像素 对比一下

4.padding-left


@charset "utf-8";
/* CSS Document */
#div1
{
	width:300px;
	height:300px;
	border:solid 5px red;
	padding-bottom:10px;
}


5.padding

四个参数 上 右 下 左

三个参数 上 左右 下

两个参数 上下 左右

我们也是用两个参数来举例

@charset "utf-8";
/* CSS Document */
#div1
{
	width:300px;
	height:300px;
	border:solid 5px red;
	padding:50px 30px;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值