在< / div>之后防止换行 [英] Prevent linebreak after </div>

查看:156
本文介绍了在< / div>之后防止换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法防止在使用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 text

thanks for your help

Update:

After no css solution led to a completly satisfying solution I will use <span> like some answers suggested

解决方案

display:inline;

OR

float:left;

OR

display: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;之后防止换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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