I’m writing example code for everything in HTML and CSS. I came across display:inline and wrote a few snippets to explain how a naturally block level element (<div>) would function as an inline element. In recent studies, I’ve found that modern browsers will automatically escape a <p> tag when it comes across a <div> within a <p>.
My JSFiddle example you can view here shows this in action. If you inspect the <p> element, you’ll find that the <div> is no-longer inside of the paragraph. I’d like to know why, as the <div> should be treated as an inline element.
Thanks!
HTML5 allows for anchor elements to wrap block level elements, but all other inline elements must not contain block level elements. The paragraph element is a strange one, as it is actually block level, but it cannot contain further block level elements (source: http://www.w3.org/TR/html4/struct/text.html#h-9.3.1).
Keep in mind that even though a block level element may behave as though it is inline if you set
display: inline;it is still a block level element.