Html div后没有换行符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4790360/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 06:21:08  来源:igfitidea点击:

No newline after div?

htmlcss-floatnewline

提问by Oliver

Is there a way to not have a newline inserted before a divwithout using float: lefton the previous element?

有没有办法在div不使用前一个float: left元素的情况下不在 a 之前插入换行符?

Maybe some tag on the divthat will just put it to the right?

也许上面的一些标签div会把它放在右边?

回答by alex

There is no newline, just the divis a block element.

没有换行符,只有div一个块元素。

You can make the divinline by adding display: inline, which may be what you want.

您可以div通过添加来进行内联display: inline,这可能是您想要的。

回答by Matthew Sant

Have you considered using spaninstead of div? It is the in-line version of div.

你有没有考虑使用span而不是div?它是 的内嵌版本div

回答by jerluc

<div style="display: inline">Is this what you meant?</div>

回答by Mateen Ulhaq

Quoting Mr Initial Man from here:

这里引用 Initial Man 先生:

Instead of this:

<div id="Top" class="info"></div><a href="#" class="a_info"></a>

Use this:

<span id="Top" class="info"></span><a href="#" class="a_info"></a>

Also, you could use this:

<div id="Top" class="info"><a href="#" class="a_info"></a></div>

取而代之的是:

<div id="Top" class="info"></div><a href="#" class="a_info"></a>

用这个:

<span id="Top" class="info"></span><a href="#" class="a_info"></a>

另外,你可以使用这个:

<div id="Top" class="info"><a href="#" class="a_info"></a></div>

And gostbustaz:

gostbustaz

If you absoultely must use a <div>, you can set

div {
    display: inline;
}

in your stylesheet.

Of course, that essentially makes the <div>a <span>.

如果您绝对必须使用 a <div>,则可以设置

div {
    display: inline;
}

在您的样式表中。

当然,这基本上使 <div>a <span>

回答by Jonas

This works like magic, use it in the CSS file on the div you want to have on the new line:

这就像魔术一样,在你想要在新行上拥有的 div 上的 CSS 文件中使用它:

.div_class {
    clear: left;
}

Or declare it in the html:

或者在 html 中声明:

<div style="clear: left">
     <!-- Content... -->
</div>

回答by Andrew

div.noWrap {
    display: inline;
    }