删除换行符 HTML

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18155809/
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 12:00:52  来源:igfitidea点击:

Remove line break HTML

html

提问by Ptr13

I'm wondering how to remove the line break in HTML. For example this code would have two Hello Worlds on top of each other. I'm sorry if I'm not good enough at programming to be in this site.

我想知道如何删除 HTML 中的换行符。例如,此代码将有两个相互叠加的 Hello World。如果我在编程方面不够好,无法进入这个站点,我很抱歉。

<p>Hello World</p>
<p>Hello World</p>

回答by David says reinstate Monica

You've got a few options:

你有几个选择:

p {
    display: inline-block;
}

JS Fiddle demo.

JS小提琴演示

Or:

或者:

p {
    display: inline;
}

JS Fiddle demo.

JS小提琴演示

If it's the white-space between the bottom of the first pand the top of the second pthat you want to remove:

如果要删除的是第一个底部p和第二个顶部之间的空白p

p {
    /*      top  right  bottom  left */
    margin: 0    0      0       0;
}

JS Fiddle demo.

JS小提琴演示

回答by user1171848

The <p>tag is a block-level element, meaning that by default it will try to take the entire width of its container. If you must use a <p>tag, you can change its behavior with CSS using "display:inline." Although, the <span>tag might work better for what you need, since it is an inline element by default.

<p>标签是块级元素,这意味着在默认情况下它会尝试采取其容器的整个宽度。如果必须使用<p>标签,可以使用 CSS 使用“display:inline”更改其行为。尽管如此,该<span>标签可能更适合您的需要,因为它默认是一个内联元素。

W3Schools has a lot of information you may find helpful.

W3Schools 提供了很多您可能会觉得有用的信息。

http://www.w3schools.com/html/html_blocks.asp

http://www.w3schools.com/html/html_blocks.asp