CSS 尺寸

使用像素值设置图像的高度

<!DOCTYPE html >
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			img.normal {
				height:auto;
			}
			img.big {
				height:120px;
			}
			p.ex {
				height:100px;
				width:100px;
			}
		</style>
	</head>
	<body>
		<img class="normal" src="logocss.gif" width="95" height="84" /><br>
		<img class="big" src="logocss.gif" width="95" height="84" />
		<p class="ex">这个段落的高和宽是 100px.</p>
		<p>这是段落中的一些文本。这是段落中的一些文本。
		这是段落中的一些文本。这是段落中的一些文本。
		这是段落中的一些文本。这是段落中的一些文本.</p>
	</body>
</html>

使用百分比设置图像的高度

<!DOCTYPE html >
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			html {
				height:100%;
			}
			
			body {
				height:100%;
			}
			
			img.normal {
				height:auto;
			}
			
			img.big {
				height:50%;
			}
			
			img.small {
				height:10%;
			}
			
		</style>
	</head>
	<body>
		<img class="normal" src="logocss.gif" width="95" height="84" /><br>
		<img class="big" src="logocss.gif" width="95" height="84" /><br>
		<img class="small" src="logocss.gif" width="95" height="84" />
	</body>
</html>

使用像素值来设置元素的宽度

<!DOCTYPE html >
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			img {width:400px;}
		</style>
	</head>
	<body>
		<img src="logocss.gif" width="95" height="84" />
	</body>
</html>

使用百分比来设置元素的宽度

<!DOCTYPE html >
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			img.normal {width:auto;}
			img.big {width:50%;}
			img.small {width:10%;}
		</style>
	</head>
	<body>
		<img class="normal" src="logocss.gif" width="95" height="84" /><br>
		<img class="big" src="logocss.gif" width="95" height="84" /><br>
		<img class="small" src="logocss.gif" width="95" height="84" />
	</body>
</html>

设置元素的最大高度

<!DOCTYPE html >
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p {
				max-height:50px;
				background-color:yellow;
			}
		</style>
	</head>
	<body>
		<p>这一段的最大高度设置为50 px。这一段的最大高度设置为50 px。这一段的最大高度设置为50 px。这一段的最大高度设置为50 px。这一段的最大高度设置为50 px。这一段的最大高度设置为50 px。这一段的最大高度设置为50 px。这一段的最大高度设置为50 px。这一段的最大高度设置为50 px。这一段的最大高度设置为50 px。</p>
	</body>
</html>

使用像素值设置元素的最大宽度

<!DOCTYPE html >
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p {
				max-width:100px;
				background-color:yellow;
			}
		</style>
	</head>
	<body>
		<p>这一段的最大宽度设置为100 px。</p>
	</body>
</html>

使用百分比设置元素的最大宽度

<!DOCTYPE html >
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p {
				max-width:20%;
				background-color:yellow;
			}
		</style>
	</head>
	<body>
		<p>This is some text. This is some text. This is some text.
		This is some text. This is some text. This is some text.
		This is some text. This is some text. This is some text.</p>
	</body>
</html>

设置元素的最低高度

<!DOCTYPE html >
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p {
				min-height:100px;
				background-color:yellow;
			}
		</style>
	</head>
	<body>
		<p>这段的最小高度设置为100 px。</p>
	</body>
</html>

使用像素值设置元素的最小宽度

<!DOCTYPE html >
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p {
				min-width:150px;
				background-color:yellow;
			}
		</style>
	</head>
	<body>
		<p>这个段落的最小宽度设置为 150px。</p>
	</body>
</html>

 

使用百分比设置元素的最小宽度

<!DOCTYPE html >
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p {
				min-width:200%;
				background-color:yellow;
			}
		</style>
	</head>
	<body>
		<p>This is some text. This is some text. This is some text.
		This is some text. This is some text. This is some text.
		This is some text. This is some text. This is some text.</p>

		<img src="logocss.gif" width="95" height="84" />
	</body>
</html>

参考:

https://www.yuque.com/docs/share/2d9566e8-5709-4bf8-81a5-b1517c917eb8

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值