当前位置:   article > 正文

CSS之block, inline_css block是什么意思

css block是什么意思

CSS之block, inline

block:块级元素

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的元素标签

  1. <address>//定义地址
  2. <caption>//定义表格标题
  3. <dd> //定义列表中定义条目
  4. <div> //定义文档中的分区或节
  5. <dl> //定义列表
  6. <dt> //定义列表中的项目
  7. <fieldset> //定义一个框架集
  8. <form> //创建 HTML 表单
  9. <h1> //定义最大的标题
  10. <h2> // 定义副标题
  11. <h3> //定义标题
  12. <h4> //定义标题
  13. <h5> //定义标题
  14. <h6> //定义最小的标题
  15. <hr> //创建一条水平线
  16. <legend> //元素为 fieldset 元素定义标题
  17. <li> //标签定义列表项目
  18. <noframes> //为那些不支持框架的浏览器显示文本,于 frameset 元素内部
  19. <noscript> //定义在脚本未被执行时的替代内容
  20. <ol> //定义有序列表
  21. <ul> //定义无序列表
  22. <p> //标签定义段落
  23. <pre> //定义预格式化的文本
  24. <table> //标签定义 HTML 表格
  25. <tbody> //标签表格主体(正文)
  26. <td> //表格中的标准单元格
  27. <tfoot> //定义表格的页脚(脚注或表注)
  28. <th> //定义表头单元格
  29. <thead> //标签定义表格的表头

 

inline:行内元素或有称为内联元素

官方解释:

“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的元素标签

  1. <a> //标签可定义锚
  2. <abbr> //表示一个缩写形式
  3. <acronym> //定义只取首字母缩写
  4. <b> //字体加粗
  5. <bdo> //可覆盖默认的文本方向
  6. <big> //大号字体加粗
  7. <br> //换行
  8. <cite> //引用进行定义
  9. <code> // 定义计算机代码文本
  10. <dfn> //定义一个定义项目
  11. <em> //定义为强调的内容
  12. <i> //斜体文本效果
  13. <img> //向网页中嵌入一幅图像
  14. <input> //输入框
  15. <kbd> //定义键盘文本
  16. <label> //标签为 input 元素定义标注(标记)
  17. <q> //定义短的引用
  18. <samp> //定义样本文本
  19. <select> // 创建单选或多选菜单
  20. <small> //呈现小号字体效果
  21. <span> //组合文档中的行内元素
  22. <strong> //加粗
  23. <sub> //定义下标文本
  24. <sup> //定义上标文本
  25. <textarea> //多行的文本输入控件
  26. <tt> //打字机或者等宽的文本效果
  27. <var> // 定义变量

 

总结

1.两种元素可以通过 display 进行转换

2.行内块元素(inline-block):结合的行内和块级的优点,既可以设置长宽,可以让padding和margin生效,又可以和其他行内元素并排。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/837850
推荐阅读
  

闽ICP备14008679号