Search code examples
wysiwygmarginparagraphepiserver

Prevent EPiServer from wrapping content in <p> tags


I'm working on a site in EPiServer, and whenever I create a page property with the type set to "XHTML string" (which uses the WYSIWYG content editor in Edit mode), it wraps all content in <p> tags.

Is there any way to prevent this from happening? I can't remove the paragraph margins universally through my CSS (e.g. p {margin: 0 !important;}) since I do need the margins for actual paragraphs of text. I've even tried going to the HTML source view in the editor and manually deleting the <p> tags that it generates, but it immediately adds them back in when I save!

It doesn't happen when the property type is either a long or short string, but that's not always an option since the content might contain images, dynamic controls, etc.

This is becoming a real nuisance since it's very hard to achieve the layout I need when basically every element on the page has extra margins applied to it.


Solution

  • I discovered that while I can't remove the <p> tags from the source view (because it adds them back in automatically), if I replace them with <div> tags, it'll leave things alone. It does mean that I've got an extra <div> wrapping some elements that I don't really need, but at least a <div> doesn't add margins like a <p> does, so...good enough!