Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use an <h2> tag </h2> inside a <p></p> in the middle of a text? [duplicate]

Tags:

html

text

css

xhtml

I want to do something like this:

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

I disabled margin and padding for the h2 but it still breaks the line before and after the h2 tag. How can I use the h2 tag in the middle of a text and make it look like if it was a normal word, just like < b > does?

The doctype of my html document is "XHTML 1.0 Transitional"

like image 601
heresma Avatar asked Jan 13 '11 01:01

heresma


People also ask

How do you center an h2 in HTML?

Centering an HTML Element Type with the Text-Align Property Then you'd use the type selector h2 and set the text-align property to center. You don't have to add any more code to align the paragraphs — by default, they'll be left aligned.

How do I center h2 inside a div?

Set the border for the <div> by using the border property and set the values of border-width, border-style, and border-color properties. Choose colors for the <h2> and <h3> tags. Use the text-align property with its "center" value for the <h2> and <h3> tags for aligning the text to the center.

What is the use of h2 tag in HTML?

An H2 tag marks the first sub-heading after your document's main heading. It defines the second-level headings on your webpage. Like an H1 tag, an H2 tag also appears larger than the rest of your main body text.

How do you write an h2 tag?

The <h2> tag is written as <h2> </h2> with the heading text inserted between the start and end tags.


3 Answers

It is not valid to have a h2 inside of a p.

Aside from that, and to answer your question, a h2 is a block level element. Making it an inline level element will cause it to behave similarly to how you describe the b tag acting.

p h2{display:inline}

As I said above though, the HTML you've given is invalid.

like image 80
Jamie Dixon Avatar answered Oct 10 '22 19:10

Jamie Dixon


It's not appropriate to use a tag that means "heading" within body text. The <h..> tags are logical tags; their use imparts meaning to the enclosed text -- namely, that the text is a section heading.

Although you could use the display: inline attribute, consider using a more appropriate tag, or even a <span> tag.

like image 44
Barry Brown Avatar answered Oct 10 '22 18:10

Barry Brown


Don't, the whole point of is that it's a header. Headers are on their own line. Instead, use CSS. Say text and then in a CSS file, choose a font size.

like image 3
codersarepeople Avatar answered Oct 10 '22 18:10

codersarepeople