是否有关于“何时使用 display:block when :inline 和when :inline-block”的指南?为什么?

发布于 2024-09-06 08:02:01 字数 152 浏览 13 评论 0原文

您知道关于“何时使用 display:block:inline 和何时 :inline-block”的好文章吗?为什么?

当我们必须覆盖显示时:??通过任何 HTML 标签/元素的 css?

Do you know any good article on "When to use display:block when :inline and when :inline-block" and why?

and when we will have to override display:?? through css for any HTML tag/element?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

恋竹姑娘 2024-09-13 08:02:01

inline - 将元素视为内联文本块。 widthheight 没有意义

block - 将元素视为矩形。可以指定 widthheight

inline-block - 使元素与文本内联流动,但允许 width 和要指定的高度

无论如何,元素默认为其中之一。例如:

-> 内联

->

inline - Treats the element as though it were an inline chunk of text. width and height are meaningless

block - Treats the element as as rectangle. width and height can be specified

inline-block - Flows a element inline with the text, but allows width and height to be specified.

Elements default to one of these anyway. For example:

<span>, <em>, <strong> -> inline

<div>, <p> -> block

苏璃陌 2024-09-13 08:02:01

块和内联的用例非常明显。如果您想将样式应用于一小段文本(例如几个单词),请使用内联,并为具有宽度/高度的矩形区域使用块。

至于内联块,它自然地用于图像。当您想让小块像常规文本一样从左到右、从上到下流动,但仍然像块一样时,它非常有用。

注意:在 90% 的情况下,您不需要指定 display 属性,只需使用带有类的适当元素,例如 <; em> 表示内联,

表示块。它发挥作用的主要方式是当使用 Javascript 隐藏内容时,您只需将元素恢复为其原始/自然显示属性。

The use cases for block and inline are pretty obvious. Use inline if you want to apply a style to a short span of text (e.g. a few words), and use block for rectangles areas with width/height.

As for inline-block, it's used naturally for images. It's useful when you want to have small blocks flowing left-to-right, top-to-bottom like regular text, but still have them like blocks.

Note: in 90% of cases you don't need to specify the display property, just use appropriate elements with classes, like <strong> or <em> for inline, <div> or <p> for blocks. The main way it comes into play is when hiding stuff with Javascript, you just need to revert the element to its original/natural display attribute.

你如我软肋 2024-09-13 08:02:01

quirksmode.org 有一个很好的解释和屏幕截图:

http://www.quirksmode.org/css/display .html

quirksmode.org has a good explanation with screenshots:

http://www.quirksmode.org/css/display.html

神魇的王 2024-09-13 08:02:01

默认情况下,分区显示为块。这会将其放在自己的线上并扩展以填充其容器。内联元素基本上将其划分为一个跨度(在默认状态下)。您无法再对其应用太多任何内容,并且它会与任何文本内联显示。你可以得到两者之间的中位数:inline-block。这允许在分区上完成更多样式设置,包括设置宽度和高度,但仍然显示与文本内联的“块”,有点像图像。

因此,内联、内联块和块更像是元素的级别,每个级别都具有可以/不能应用于该元素的某些样式。

By default a division displays as a block. This puts it on its own line and expands to fill its container. An inline element basically makes a division into a span (in its default state). You can't apply much anything to it anymore and it displays inline with any text. You can get a median between the two: inline-block. This allows more styling to be done on the division, including setting a width and height, but still displays the 'block' inline with the text, sort of like an image.

So, inline, inline-block, and block are more like levels of an element, each with certain styles that can/cannot be applied to the element.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文