Page MenuHomePhabricator

Use <span> rather than <div> for things that are not meant to be block elements
Closed, ResolvedPublic

Description

We should use <span> rather than <div> for things that are not meant to be block elements. Rule of thumb: if we set the 'display' in CSS to anything other than 'block' or 'table', it should probably be a <span>.

Benefits:

  • Better usability in text browsers
  • Better compatibility with tools with none or limited support for CSS (for example: copy-paste into a text editor)
  • Better flexibility of PHP widgets
  • Users can just kill the styles if they really really hate it ;)

To elaborate on last point – HTML enforces some element nesting rules, for example defining some elements as block or inline, and defining that some elements can only have block or inline content. For example, a <p> element contains inline content and thus can't have block elements like <div> nested inside. (This doesn't matter for JS, where you can put anything inside anything using DOM operations.)

Currently, a ButtonWidget generates a <div>, which means you can't display an OOjs UI PHP button inside a HTML paragraph (if you try, complicated rules kick in during HTML parsing, and the effect is that essentially the paragraph gets split in two). This is annoying and not obvious to debug. I ran into this myself when working on T101666: Create parser tag(s) that render OOUI PHP widgets.

Event Timeline

Change 340268 had a related patch set uploaded (by Bartosz Dziewoński; owner: Bartosz Dziewoński):
Use <span> rather than <div> for inline-ish widgets

https://gerrit.wikimedia.org/r/340268

Change 340269 had a related patch set uploaded (by Bartosz Dziewoński; owner: Bartosz Dziewoński):
FieldLayout: Use <span> rather than <div> when possible

https://gerrit.wikimedia.org/r/340269

Volker_E edited projects, added OOUI (OOjs-UI-0.20.0); removed OOUI.
Volker_E removed a project: Patch-For-Review.
Volker_E removed a subscriber: gerritbot.

Change 340268 merged by jenkins-bot:
[oojs/ui] Use <span> rather than <div> for inline-ish widgets

https://gerrit.wikimedia.org/r/340268

Change 340269 merged by jenkins-bot:
[oojs/ui] FieldLayout: Use <span> rather than <div> when possible

https://gerrit.wikimedia.org/r/340269