user1050619
user1050619

Reputation: 20856

Paragraph tag being displayed in new line

I need value "1" to be displayed adjacent to "Id" field but its displaying in a new line.The

tag is supposed to be inline not sure why its being moved to new line.

jsfiddle

HTML

<b>Id    : <p id="productid">1</p></b>

Upvotes: 0

Views: 39

Answers (2)

Oriol
Oriol

Reputation: 288000

A <p> element is a paragraph, which by default is a block element.

In this case, you can't use <p> because:

  • It is not allowed inside <b> elements (because <p> can only be used where flow content is expected, but the content model of <b> is phrasing content). Always remember to validate your code.
  • Semantically, it's clear that it isn't a paragraph.

I suggest using

<b>Id: <span id="productid">1</span></b>

Demo

Upvotes: 1

Kai Qing
Kai Qing

Reputation: 18833

#productid{
    display:inline-block;
}

p is a block level element by default. You can set it to display inline-block to make it do as you describe using basic css.

I'm not sure if you are unable to access css, so in case you cannot, see oriol's answer. No reason not to just make it a span.

Bit of a side note, it is a little odd to put a p tag inside a b tag. Technically you CAN do this, but it looks like using a span tag is the more proper way to handle this.

Upvotes: 0

Related Questions