I'm a big fan of reveal.js. It is a lightweight HTML-based presentation framework that just works well for me. I switched over to it a while ago and enjoy working with it. Every now and then though I run into an issue that is a bit hard to handle with it. Yesterday I was working on my cfObjective presentation and created the slide you see below.

As you can see, the most important part of the slide is covered by the header. This is unacceptable! Unfortunately, it is difficult to reposition the h1 (or h2) element within a Reveal.js slide. If you set the position to absolute and use 0/0 for top and left, you end up at the top left of the section element, not the top left of the screen. You can use negative values, but that felt wrong to me, and I was worried about what would happen on a smaller screen when I presented.

I raised the issue on Twitter (where all important things should be discussed, am I right?) and Rey Villalobos (@planetoftheweb) came up with a good solution. He was ok with me sharing this on my blog, but note that any mistakes in the description are entirely hismy fault.

First, you need to add an element to handle the header, but place it outside the div for your slides.

<!-- In between the <div="reveal"> and the <div class="slides">-->
<header style="position: absolute;top: 50px; left: 100px; z-index:500; font-size:100px;background-color: rgba(0,0,0,0.5)"></header>
<!-- In between the <div="reveal"> and the <div class="slides">-->

(Note - those top and left values are a bit arbitrary. Ditto for the RGBA color.)

Then - for each slide - use CSS to specify the content for the element.

<section data-state="header1">
<style>.header1 header:after { content: "Header 1 Example"; }</style>
<p>header1 example</p>

Note - when you add a state attribute to a slide in Reveal, the framework automatically applies the state name to the class of the div wrapping all the slides, which means it also impacts that earlier header. As soon as you leave that slide, the class is removed, which means the content dynamically added via CSS (you did know you could do that, right?) is also removed.

Here is the updated slide.

There is one small caveat to this post that I don't have an answer for yet (but check the comments, going to bug Rey until he can figure out a fix) - how to modify the position of the header so it is right aligned. You could probably just use a second DOM element (a div perhaps) but that seems wrong.