How to move this Container to the top of the page

Many thanks to Ronak who helped me with the answer but I thought I would expand it in case anyone gets an error like me.

First of all, make sure the first line of your Reference container in default.xml looks like this

<container name="topbar.container" label="topbar" as="topbar" htmlTag="div" htmlClass="topbar">

Now got to your home.xml or whatever you call your main page layout and make sure the container you are trying to move to the top has a layout something like this

<container name="topbar.container" as="topbar_container" label="Page topbar Container" htmlTag="topbar" htmlClass="page-topbar" before="-"/>

now go back to your default.xml and input this anywhere inside of the body tags but outside of anything else.

<move element="topbar.container" destination="header.container" before="-"/>

Make sure your container name is the same on both pages or you will get a error or it just won't work, trust me it took me hours to work that out.

Tags:

Magento2