设置内联元素的宽度 [英] Setting the width of inline elements

查看:158
本文介绍了设置内联元素的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


您可以设置< span> < em> < strong> ,但在您将它们放置之前,您不会注意到任何效果。

You can set the width of inline elements like <span>, <em> and <strong>, but you won’t notice any effect until you position them.

a)我以为内联的inline元素的宽度不能设置?

a) I thought the width of inline an inline element can’t be set?

b)假设width可以设置 - 我们不会注意到任何效果(因此我们指定的宽度),直到我们定位inline元素。位置如何/在哪里?

b) Assuming width can be set - we won’t notice any effects ( thus the width we specify ) until we position inline element. Position how/where?

c)为什么只有当我们定位它们时,内联元素的宽度才会显现?

c) Why is the width of inline elements apparent only when we "position" them?

推荐答案

正如其他人提到的,设置内联元素的宽度(或某些其他位置相关属性)然后将该元素显示为块元素。

As others have mentioned, setting the width (or some other position-related property) of an inline element will cause the browser to then display the element as a block element.

您可以使用CSS display 属性来显式声明此类行为。最常见的设置是 display:inline (默认), display:block :none
display 属性的完整引用可用此处

You can explicitly declare this sort of behavior through using the CSS display property. The most common settings are display: inline (default), display: block, and display: none.
A full reference for the display property is available here.

但是,应注意 HTML 4.01规范不鼓励使用覆盖HTML元素的常规解释:



However, it should be noted that the HTML 4.01 specification discourages the use of "overriding the conventional interpretation of HTML elements":


样式表提供了
的方法指定任意
元素的渲染,包括元素
呈现为块或内联。在
中一些情况下,例如列表元素的内联样式
,这可能是
适当,但一般来说,
作者不鼓励从
覆盖常规
以这种方式解释
中的HTML元素。

Style sheets provide the means to specify the rendering of arbitrary elements, including whether an element is rendered as block or inline. In some cases, such as an inline style for list elements, this may be appropriate, but generally speaking, authors are discouraged from overriding the conventional interpretation of HTML elements in this way.

这篇关于设置内联元素的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆