Html 删除 <h1> 标签后的换行符?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9361108/
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
Removing newline after <h1> tags?
提问by Hyman Wilsdon
I am having a problem with removing linebreaks after the <h1>
tag, as everytime it prints, it adds a line break straight after it, so something like <h1>Hello World!</h1> <h2>Hello Again World!</h2>
prints out like this:
我在删除<h1>
标签后的换行符时遇到了问题,因为每次打印时,它都会在它之后直接添加一个换行符,所以像这样<h1>Hello World!</h1> <h2>Hello Again World!</h2>
打印出来:
Hello World!
Hello Again World!
I am unsure on what tags I need to change in CSS, but I expect it's something to do with the padding or margins
我不确定我需要在 CSS 中更改哪些标签,但我希望这与填充或边距有关
I also want to keep the vertical padding if at all possible.
如果可能的话,我也想保留垂直填充。
回答by Ben Lee
Sounds like you want to format them as inline. By default, h1
and h2
are block-level elements which span the entire width of the line. You can change them to inline with css like this:
听起来您想将它们格式化为内联格式。默认情况下,h1
和h2
是跨越整个线宽的块级元素。您可以将它们更改为与 css 内联,如下所示:
h1, h2 {
display: inline;
}
Here's an article that explains the difference between block
and inline
in more detail: http://www.webdesignfromscratch.com/html-css/css-block-and-inline/
下面是解释之间的区别的文章block
,并inline
详细:http://www.webdesignfromscratch.com/html-css/css-block-and-inline/
To maintain vertical padding, use inline-block
, like this:
要保持垂直填充,请使用inline-block
,如下所示:
h1, h2 {
display: inline-block;
}
回答by tkone
<h1>
tags have {display: block}
set. They are block-level elements. To turn this off:
<h1>
标签已经{display: block}
设置。它们是块级元素。要关闭此功能:
{display: inline}
回答by Jacek
I just solved this problem by setting h1 margin value to minus in html style section. It works perfecly for my needs.
我刚刚通过在 html 样式部分将 h1 边距值设置为减来解决了这个问题。它非常适合我的需求。
<style>
h1 {
display: block;
font-size: 0.9em;
margin-top: -1.91em;
margin-bottom: -1.91em;
margin-left: 0;
margin-right: 0;
font-weight: bold;
}
</style>
<h1 style="text-align:center"> Headline </h1>
回答by Hamida Almangush
<style>
h1 {
padding: 0px;
margin: 0px;
}
</style>