Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I put DIV in P?

Tags:

How can I put div in paragraph? I changed the display to inline, but the browser divide the base paragraph to two element, and div will not member of paragraph.

like image 802
János Avatar asked Mar 26 '11 10:03

János


People also ask

Can div be nested inside P?

In HTML, you can nest not only inline tags but also almost any other combination of tags. This way when you apply some custom styling to the <div> tag, it will be applied to the nested <p> tags as well.

How do you style a P tag inside a div?

div p {.../*styles for p-tags inside a div*/...} will choose both p inside a div in your case.

Can I put div in form?

It is completely acceptable to use a DIV inside a <form> tag. If you look at the default CSS 2.1 stylesheet, div and p are both in the display: block category.

Can you put div in TD?

Using a div instide a td is not worse than any other way of using tables for layout. (Some people never use tables for layout though, and I happen to be one of them.) If you use a div in a td you will however get in a situation where it might be hard to predict how the elements will be sized.


2 Answers

form the w3 site:

The P element represents a paragraph. It cannot contain block-level elements (including P itself).

like image 120
Gergely Fehérvári Avatar answered Sep 29 '22 09:09

Gergely Fehérvári


no you cannot nest anything other than an inline element in a <p> if you want the code to validate

from the property def:

<!ELEMENT P - O (%inline;)* -- paragraph -->

I know it's hard to understand those recs at times, but the bit in brackets means the <p> can only contain inline elements

you can (and should) use a <span> inside a <p> and if required you could change it's CSS display property to block or inline-block and that would be perfectly valid, as CSS properties do not change the actual definitions of an element.. in your case it sounds like you need an inline element so just use a <span>

like image 24
clairesuzy Avatar answered Sep 29 '22 09:09

clairesuzy