Html 如何防止 DIV 标签开始新行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1826735/
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
How do I prevent DIV tag starting a new line?
提问by undefined
I want to output a single line of text to the browser that contains a tag. When this is rendered it appears that the DIV causes a new line. How can I include the content in the div tag on the same line - here is my code.
我想将一行文本输出到包含标签的浏览器。呈现此内容时,DIV 似乎导致了一个新行。如何在同一行的 div 标签中包含内容 - 这是我的代码。
<?php
echo("<a href=\"pagea.php?id=$id\">Page A</a>")
?>
<div id="contentInfo_new">
<script type="text/javascript" src="getData.php?id=<?php echo($id); ?>"></script>
</div>
I have tried to tidy it up here. How can I have this display on a single line?
我试图在这里整理它。我怎样才能在一行上显示这个?
回答by SLaks
The div
tag is a block element, causing that behavior.
该div
标签是块元素,造成这种行为。
You should use a span
element instead, which is inline.
您应该改用span
内联元素。
If you reallywant to use div
, add style="display: inline"
. (You can also put that in a CSS rule)
如果您真的要使用div
,请添加style="display: inline"
. (你也可以把它放在 CSS 规则中)
回答by Shivanshu
I am not an expert but try white-space:nowrap;
我不是专家,但尝试 white-space:nowrap;
The white-space property is supported in all major browsers.
所有主要浏览器都支持 white-space 属性。
Note: The value "inherit"
is not supported in IE7 and earlier. IE8 requires a !DOCTYPE
. IE9 supports "inherit"
.
注意:"inherit"
IE7 及更早版本不支持该值。IE8 需要一个!DOCTYPE
. IE9 支持"inherit"
.
回答by cobbal
div
is a block element, which always takes up its own line.
div
是一个块元素,它总是占据自己的一行。
use the span
tag instead
改用span
标签
回答by Franz
Add style="display: inline"
to your div.
添加style="display: inline"
到您的 div。
回答by Jimmeh
use float:left on the div and the link, or use a span.
在 div 和链接上使用 float:left ,或使用跨度。
回答by Jithjob Ignatious
Use css property - white-space: nowrap;
使用 css 属性 - white-space: nowrap;
回答by dfilkovi
<div style="float: left;">
<?php
echo("<a href=\"pagea.php?id=$id\">Page A</a>")
?>
</div>
<div id="contentInfo_new" style="float: left;">
<script type="text/javascript" src="getData.php?id=<?php echo($id); ?>"></script>
</div>
回答by user3012794
You can simply use:
您可以简单地使用:
#contentInfo_new br {display:none;}