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"
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.
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.
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.
The <h2> tag is written as <h2> </h2> with the heading text inserted between the start and end tags.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With