赞
踩
css官方解释为:
“In a block formatting context, boxes are laid out one after the other, vertically, beginning at the top of a containing block. The vertical distance between two sibling boxes is determined by the 'margin' properties. Vertical margins between adjacent block-level boxes in a block formatting context collapse.
In a block formatting context, each box's left outer edge touches the left edge of the containing block (for right-to-left formatting, right edges touch).” - 9.4.1
翻译:
“在一个块格式区域中,盒子会从包含块的顶部开始,按序垂直排列。同级盒子间的垂直距离会由“margin”属性决定。相邻两个块级盒子之间的垂直间距会遵循外边距折叠原则被折叠。
在一个块格式区域中,每个盒子的左外边缘会与包含块左边缘重合(如果是从右到左的排版顺序,则盒子的右外边缘与包含块右边缘重合)。” - 9.4.1
注意:
1.每一个元素各占一行(默认情况下,块级元素将占据这一内联方向的所有空间),可以设置长度和宽度
2.外边距折叠的情况
在规范中提到,块级元素之间的外边距会发生折叠。这意味着,如果一个具有上边距的元素排在在一个具有下边距的元素之下时,他们之间的间距不会是这两个外边距的和,即外边距会发生折叠,简单来说就是,间距与两个外边距中的较大者一样大。
默认展示为block的元素标签
- <address>//定义地址
- <caption>//定义表格标题
- <dd> //定义列表中定义条目
- <div> //定义文档中的分区或节
- <dl> //定义列表
- <dt> //定义列表中的项目
- <fieldset> //定义一个框架集
- <form> //创建 HTML 表单
- <h1> //定义最大的标题
- <h2> // 定义副标题
- <h3> //定义标题
- <h4> //定义标题
- <h5> //定义标题
- <h6> //定义最小的标题
- <hr> //创建一条水平线
- <legend> //元素为 fieldset 元素定义标题
- <li> //标签定义列表项目
- <noframes> //为那些不支持框架的浏览器显示文本,于 frameset 元素内部
- <noscript> //定义在脚本未被执行时的替代内容
- <ol> //定义有序列表
- <ul> //定义无序列表
- <p> //标签定义段落
- <pre> //定义预格式化的文本
- <table> //标签定义 HTML 表格
- <tbody> //标签表格主体(正文)
- <td> //表格中的标准单元格
- <tfoot> //定义表格的页脚(脚注或表注)
- <th> //定义表头单元格
- <thead> //标签定义表格的表头
-

官方解释:
“In an inline formatting context, boxes are laid out horizontally, one after the other, beginning at the top of a containing block. Horizontal margins, borders, and padding are respected between these boxes. The boxes may be aligned vertically in different ways: their bottoms or tops may be aligned, or the baselines of text within them may be aligned. The rectangular area that contains the boxes that form a line is called a line box.” - 9.4.2
翻译:
“在内联格式区域中,盒子会从包含块的顶部开始,按序水平排列。只有水平外边距、边框合内边距会被保留。这些盒子可以以不同的方式在垂直方向上对齐:可以底部对齐或顶部对其,或者按文字底部进行对齐。我们把包含一串盒子的矩形区域称为一个线条框。(The rectangular area that contains the boxes that form a line is called a line box.)” - 9.4.2
Inline elements display one after the other in the direction that sentences run in that particular writing mode. While we don’t tend to think of inline elements as having a box, as with everything in CSS they do. These inline boxes are arranged one after the other. If there is not enough space in the containing block for all of the boxes a box can break onto a new line. The lines created are known as line boxes.
内联元素按照句子在特定书写模式下运行的方向依次显示。虽然我们不倾向于认为内联元素有一个框,就像CSS中的所有元素一样。这些内嵌的盒子一个接一个排列。如果包含块中没有足够的空间容纳所有框,则框可以换行。创建的行称为行框。
注意:
1.一行内可以显示多个行内元素,显示不下的时候会换行
2.行内元素无法设置高度和宽度
默认展示为inline的元素标签
- <a> //标签可定义锚
- <abbr> //表示一个缩写形式
- <acronym> //定义只取首字母缩写
- <b> //字体加粗
- <bdo> //可覆盖默认的文本方向
- <big> //大号字体加粗
- <br> //换行
- <cite> //引用进行定义
- <code> // 定义计算机代码文本
- <dfn> //定义一个定义项目
- <em> //定义为强调的内容
- <i> //斜体文本效果
- <img> //向网页中嵌入一幅图像
- <input> //输入框
- <kbd> //定义键盘文本
- <label> //标签为 input 元素定义标注(标记)
- <q> //定义短的引用
- <samp> //定义样本文本
- <select> // 创建单选或多选菜单
- <small> //呈现小号字体效果
- <span> //组合文档中的行内元素
- <strong> //加粗
- <sub> //定义下标文本
- <sup> //定义上标文本
- <textarea> //多行的文本输入控件
- <tt> //打字机或者等宽的文本效果
- <var> // 定义变量

总结
1.两种元素可以通过 display 进行转换
2.行内块元素(inline-block):结合的行内和块级的优点,既可以设置长宽,可以让padding和margin生效,又可以和其他行内元素并排。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。