18

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.

Jason Weber
  • 5,653
  • 6
  • 40
  • 73

3 Answers3

18

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;
    }
jacefarm
  • 6,747
  • 6
  • 36
  • 46
6

You need to use style attribute:

<div style="display:inline">
antyrat
  • 27,479
  • 9
  • 75
  • 76
  • Hi, thanks Antyrat. I'm sure your answer isn't incorrect. But when I do:

    Kevin Smith

    The Official Kevin Smith Website
    in the WordPress widget, it still displays it on two separate lines (although there's plenty of room to display them on one line). Thank you for taking the time to respond!
    – Jason Weber Aug 15 '14 at 13:32
  • 2
    @JasonWeber you need to add this tyle attrs to h3 & h2 elements, not to div – antyrat Aug 15 '14 at 13:33
  • 1
    This answer is incorrect. Styling the wrapper 'div' will make the 'div' itself display inline, but not it's children. Also, be sure to use semi-colons after each CSS property used in an inline style. – jacefarm Aug 15 '14 at 13:38
  • @jacefarm I have showed to OP how to use inline styles. So he can use it anywhere he want. Anyway, thanks for comment about semicolons! – antyrat Aug 15 '14 at 13:43
  • This seemed to do the trick, or what I was looking for:
    Kevin Smith

    The Official Kevin Smith Website

    .... Thanks again!
    – Jason Weber Aug 15 '14 at 13:45
-2

According to the spec, you're looking for display:run-in as described in this StackOverflow question. For you, that would look like:

h2 { display:run-in; }
p  { display:block; } // default
<h2>Kevin Smith</h2>
<p>The Official Kevin Smith Website</p>

Unfortunately, that code snippet won't work. That's because, practically, most of the browsers have abandonded display:run-in, even ones that previously had it. This feature is not ready for production. It's never been supported in Firefox, and it was removed from both Safari (v8) and Chrome (v32). It does, however, describe exactly the typographical behavior you're asking for.

This question gives links to other threads that have tried workarounds.

Merchako
  • 789
  • 1
  • 8
  • 19
  • I'd appreciate more information about why this answer has been downvoted. Article on why to downvote: https://meta.stackexchange.com/questions/2451/why-do-you-cast-downvotes-on-answers – Merchako Nov 27 '18 at 22:45