Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k views
in Technique[技术] by (71.8m points)

html - Setting the width of inline elements

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) I thought the width of inline an inline element can’t be set?

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) Why is the width of inline elements apparent only when we “position” them?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...