A broken layout like that is usually caused by you either having extra open tags or extra closed tag (like you have a <div> but no corresponding </div>, or you have an extra </div> without the associated <div> earlier on). Doesn't have to be div, could be any block-level tag such as <table> too.
If you're copying templates from Wikipedia, you're going to need a handful of settings and extensions installed in order to make them work correctly. Click the links in each point for more info.
- Ensure that Tidy is enabled: $wgTidyConfig. My recommendation is to use the first example on that page under the Examples heading; it will require that the tidy PHP extension (not MediaWiki extension) is installed on your server. If Tidy is not enabled, broken layouts like the above can happen due to how the wikitext parser operates differently when not using Tidy, even if there is no actual issue with your wikitext.
- Ensure that you have installed the following MediaWiki extensions: ParserFunctions and Scribunto