Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display a header inline with paragraph text using divs or an alternative method

I have this simple snippet in a WordPress widget:

 <h3>Kevin Smith</h3><h2>The Official Kevin Smith Website</h2>

The name is changed for privacy. Is there any possible way I get get these to appear on the same line?

I'm a CSS dummy, but I've tried doing things like:

 <div display:inline><h3>Kevin Smith</h3><h2>The Official Kevin Smith Website</h2></div>

But this doesn't work for reasons that are most likely obvious to CSS gurus.

Any guidance in how I can achieve putting these on the same line would be greatly appreciated!

* UPDATED SOLUTION *

For anybody with similar issues, I just used this -- with the help of @antyrat and @jacefarm:

<div style="display:inline">Kevin Smith</div><p style="display:inline">The Official  
Kevin Smith Website</p>

That way, I was able to style the div differently than the p, and they're both inline -- which is precisely what I was attempting to achieve.

like image 249
Jason Weber Avatar asked Aug 15 '14 13:08

Jason Weber


People also ask

How do I make an inline header?

The easiest way to use this type of formatting is to type your heading text followed by your body text, in a single paragraph. Make sure the entire paragraph is formatted as body text, then select just the text that will comprise the heading. Apply the level-three heading style to this selected text.

How do I make an inline paragraph in HTML?

An inline element does not start on a new line. An inline element only takes up as much width as necessary. This is a <span> element inside a paragraph.

Are divs inline or block?

div is a “block element” (now redefined as Flow Content) and span is an “inline element” (Phrasing Content).


2 Answers

Inline styles on HTML elements are written as HTML attributes. You would use the 'style' attribute and give it a value that is wrapped in quotes. Also, you need to have a semi-colon after each CSS '[property]: [value];' pair passed into the 'style' attribute, just like you would in a standard CSS stylesheet.

    <div>
       <h3 style="display: inline;">Kevin Smith</h3>
       <h2 style="display: inline;">The Official Kevin Smith Website</h2>
    </div>

Alternatively, you could assign a class to the parent 'div' element, such as 'title', and then style the 'h3' and 'h2' tags in your CSS stylesheet, like this:

HTML

    <div class="title">
       <h3>Kevin Smith</h3>
       <h2>The Official Kevin Smith Website</h2>
    </div>

CSS

    .title h2,
    .title h3 {
      display: inline;
    }
like image 82
jacefarm Avatar answered Oct 19 '22 07:10

jacefarm


You need to use style attribute:

<div style="display:inline">
like image 38
antyrat Avatar answered Oct 19 '22 06:10

antyrat