如何在不更改<h>和<p>标签的情况下将标题和段落连接在一起。

huangapple go评论60阅读模式
英文:

How to join a heading and paragraph in without changing the <h> and <p> tags

问题

我有一个标题,在下面我有一个在<p>标签中的句子。下面给出的是代码。

<!DOCTYPE html>
<html>
<body>

<h1>The p element</h1>

<p>This is a paragraph.</p>

</body>
</html>

上面的代码给出了以下结果:

The p element
This is a paragraph.

我的期望结果是:

The p element This is a paragraph.

我也不想改变&lt;h&gt;&lt;p&gt;标签。

英文:

i have a header and a below that i have sentence in a <p> tag. The below given is the code.

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;

&lt;h1&gt;The p element&lt;/h1&gt;

&lt;p&gt;This is a paragraph.&lt;/p&gt;

&lt;/body&gt;
&lt;/html&gt; 

The above code gives gives me the below result:

The p element
This is a paragraph.

My expected result is:

The p element This is a paragraph.

i also don't want to change the &lt;h&gt; and &lt;p&gt; tags

答案1

得分: 2

尝试应用 display: inline 属性。

编辑

您可以将其应用于两个元素:

<h1 style="display:inline">The p element</h1>
<p style="display:inline">This is a paragraph.</p>

或者,使用CSS:

p, h1 {
  display: inline;
}

示例

英文:

Try applying the display: inline property.

EDIT

You would apply it to both elements:

&lt;h1 style=&quot;display:inline&quot;&gt;The p element&lt;/h1&gt;
&lt;p style=&quot;display:inline&quot;&gt;This is a paragraph.&lt;/p&gt;

Or, using CSS:

p, h1 {
  display: inline;
}

Example

答案2

得分: 1

Adding CSS would do the magic. Here is an example:

<!DOCTYPE html>
<html>
<style>
.headline h1, .headline p {
    display: inline;
}
</style>
<body>
  <div class="headline">
    <h1>The p element</h1>
    <p>This is a paragraph.</p>
  </div>
</body>
</html>
英文:

Adding CSS would do the magic. Here is an example:

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;style&gt;
.headline h1, .headline p {
    display: inline; 
}
&lt;/style&gt;
&lt;body&gt;
  &lt;div class=&quot;headline&quot;&gt;
    &lt;h1&gt;The p element&lt;/h1&gt;
    &lt;p&gt;This is a paragraph.&lt;/p&gt;
  &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;  

huangapple
  • 本文由 发表于 2023年1月6日 11:44:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026731.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定