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
No newline after div?
提问by Oliver
Is there a way to not have a newline inserted before a div
without using float: left
on the previous element?
有没有办法在div
不使用前一个float: left
元素的情况下不在 a 之前插入换行符?
Maybe some tag on the div
that will just put it to the right?
也许上面的一些标签div
会把它放在右边?
回答by alex
There is no newline, just the div
is a block element.
没有换行符,只有div
一个块元素。
You can make the div
inline by adding display: inline
, which may be what you want.
您可以div
通过添加来进行内联display: inline
,这可能是您想要的。
回答by Matthew Sant
Have you considered using span
instead 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:
If you absoultely must use a
<div>
, you can setdiv { 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;
}