本文介绍了在&lt; / div&gt;之后防止换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 是否有办法防止在使用css的div后换行? 例如我有 < div class =label>我的标签:< / div> < div class =text>我的文字< / div> 并希望显示为: 我的标签:我的文字 感谢您的帮助 更新: 在没有css解决方案导致完全满意的解决方案后,我将使用 display:inline; code> 或 float:left; 或 display:inline-block; - 可能无法在所有浏览器上使用。 这里使用 div 我建议一个 span ,因为它是一个内联级元素,而 div 是一个块级元素。 请注意,上述每个选项的工作方式不同。 display:inline; 会将 div 转换为 / code>。它不受 margin-top , margin-bottom , padding-top , padding-bottom , height 等。 float:left; 将 div 保留为块级元素。它仍然占用空间,就像它是一个块,但宽度将适合内容(假设 width:auto; )。 display:inline-块; 是最好的两个世界选项。 div 被视为块元素。它响应所有 margin , padding 和 height 对于块元素所期望的规则。但是,它被视为内联元素,用于放置在其他元素中。 阅读此了解更多信息。 Is there a way to prevent a line break after a div with css?For example I have <div class="label">My Label:</div> <div class="text">My text</div>and want it to display like: My Label: My textthanks for your helpUpdate:After no css solution led to a completly satisfying solution I will use <span> like some answers suggested 解决方案 display:inline;ORfloat:left;ORdisplay:inline-block; -- Might not work on all browsers.What is the purpose of using a div here? I'd suggest a span, as it is an inline-level element, whereas a div is a block-level element.Do note that each option above will work differently.display:inline; will turn the div into the equivalent of a span. It will be unaffected by margin-top, margin-bottom, padding-top, padding-bottom, height, etc.float:left; keeps the div as a block-level element. It will still take up space as if it were a block, however the width will be fitted to the content (assuming width:auto;). It can require a clear:left; for certain effects.display:inline-block; is the "best of both worlds" option. The div is treated as a block element. It responds to all of the margin, padding, and height rules as expected for a block element. However, it is treated as an inline element for the purpose of placement within other elements.Read this for more information. 这篇关于在&lt; / div&gt;之后防止换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-02 22:52