CSS教程
- CSS 教程
- CSS 简介
- CSS 语法
- CSS id 和 class选择器
- CSS 创建
- CSS Background(背景)
- CSS 文本格式
- CSS 字体
- CSS 链接
- CSS 列表
- CSS 表格
- CSS 盒子模型
- CSS 边框
- CSS 轮廓(outline)
- CSS margin(外边距)
- CSS padding(填充)
- CSS 分组 和 嵌套 选择器
- CSS 尺寸 (Dimension)
- CSS Display(显示)
- CSS Position(定位)
- CSS 布局 - Overflow
- CSS Float(浮动)
- CSS 布局 - 水平 & 垂直对齐
- CSS 组合选择符
- CSS 伪类(Pseudo-classes)
- CSS 伪元素
- CSS 导航栏
- CSS 下拉菜单
- CSS 提示工具(Tooltip)
- CSS 图片廊
- CSS 图像透明/不透明
- CSS 图像拼合技术
- CSS 媒体类型
- CSS 属性 选择器
- CSS 表单
- CSS 计数器
- CSS 网页布局
- CSS !important 规则
CSS 尺寸 (Dimension) 属性允许你控制元素的高度和宽度。同样,它允许你增加行间距。
更多实例
1.设置元素的高度
这个例子演示了如何设置不同元素的高度。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>饭桶教程(kuaikuaixuan.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>
2.使用百分比设置图像的高度
这个例子演示了如何使用百分比值设置元素的高度。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>饭桶教程(kuaikuaixuan.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>
3.使用像素值来设置元素的宽度
本例演示如何使用像素值来设置元素的宽度。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>饭桶教程(kuaikuaixuan.com)</title> <style> img {width:200px;} </style> </head> <body> <img src="logocss.gif" width="95" height="84" /> </body> </html>
4.设置元素的最大高度
此示例演示如何设置元素的最大高度。
<html> <head> <meta charset="utf-8"> <title>饭桶教程(kuaikuaixuan.com)</title> <style type="text/css"> p { max-height:50px; background-color:yellow; } </style> </head> <body> <p>本段落的最大高度被设置为 50px。 本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。本段落的最大高度被设置为 50px。</p> </body> </html>
5.使用百分比来设置元素的最大宽度
本例演示如何使用百分比值来设置元素的最大宽度。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>饭桶教程(kuaikuaixuan.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>
6.设置元素的最低高度
此示例演示如何设置元素的最小高度。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>饭桶教程(kuaikuaixuan.com)</title> <style> p { min-height:100px; background-color:yellow; } </style> </head> <body> <p>这段的最小高度设置为100 px。</p> </body> </html>
7.使用像素值设置元素的最小宽度
这个例子演示了如何使用像素值设置元素的最小宽度。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>饭桶教程(kuaikuaixuan.com)</title> <style> p { min-width:150px; background-color:yellow; } </style> </head> <body> <p>这个段落的最小宽度设置为 150px。</p> </body> </html>
所有CSS 尺寸 (Dimension)属性
属性 | 描述 |
---|---|
height | 设置元素的高度。 |
line-height | 设置行高。 |
max-height | 设置元素的最大高度。 |
max-width | 设置元素的最大宽度。 |
min-height | 设置元素的最小高度。 |
min-width | 设置元素的最小宽度。 |
width | 设置元素的宽度。 |
© 2025 Copyright: kuaikuaixuan.com
京ICP备14015652号-3
网址导航