Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

H1 tag and P tag on the same line?

Tags:

I'm trying to place some text inside the P tag after the closing H1 tag like this:

Headline And here are the text right after....

But I can't get it to work. I made this CSS, but something is perhaps missing?

CSS:

p.start {     font-family: 'Open Sans', sans-serif;     font-size: 16px;     line-height: 28px;     text-align: justify;     display: inline; }  h1.start {     font-family: 'Open Sans', sans-serif;     font-size: 16px;     line-height: 28px;     margin: 0;     display: inline-block; } 

HTML:

<div id="containerIntro">     <h1 class="start">Headline </h1>     <p class="start">Text......</p> </div> 
like image 460
3D-kreativ Avatar asked Apr 25 '12 16:04

3D-kreativ


People also ask

Can we use h1 tag in P tag?

The header tags are block-level elements, and cannot go inside <p> tags even when you style them to display inline.

How do I display two tags on the same line?

To display multiple div tags in the same line, we can use the float property in CSS styles. The float property takes left, right,none(default value) and inherit as values. The value left indicates the div tag will be made to float on the left and right to float the div tag to the right.

How do you put a heading and paragraph on the same line in HTML?

Just make your <h1> display:inline. This way, it will render in the normal text flow.


2 Answers

So if you had:

<div id="containerIntro">     <h1>Headline</h1>     <p>And here the text right after...</p> </div> 

Your CSS would have to look something like this:

#containerIntro h1, #containerIntro p {     display: inline;     vertical-align: top;     font-family: 'Open Sans', sans-serif;     font-size: 16px;     line-height: 28px; } 

See http://jsfiddle.net/F3Bcd/3/.

like image 169
Olly Hodgson Avatar answered Sep 19 '22 18:09

Olly Hodgson


Both <p> and <h1> elements are block level - that means they take up the complete width of their container. You can try floating both elements to the left. This stacks them up on each other to the left side and also converts them to inline elements.

like image 25
Surreal Dreams Avatar answered Sep 20 '22 18:09

Surreal Dreams