19

I'm using reveal.js and trying to sort out how to force my slides to the top left-most corner of the page. That seems like it should be straightforward, but when I use the Element inspector it so radically changes the page that I can't even begin to zero in on how to move the slides up to the top.

Adding this to my theme:

.reveal .slides>section,
.reveal .slides>section>section {
    padding: 0;}

Bumped it up a smidge (reveal.css has the padding set to 20px 0) but there's still white space at the top of each slide.

5 Answers 5

23

To move your slides to the top is just a configuration option of reveal.js.

Reveal.initialize({
    center: false
}

I haven't figured it out how to move them to the left though.

Horizontal alignment can be done from CSS:

.reveal .slides { margin: 0; }
3
  • +1 — For horizontal alignment, all the usual suspects apply: text-align, margin: 0 auto, position: absolute; left: 50%; margin-left: -[halfWidth]px... Apr 28, 2015 at 6:53
  • I managed to move the content to the left by adding .reveal .slides { margin: 0; } to the template.
    – riezebosch
    Apr 28, 2015 at 9:18
  • I had to do the 0 margin, too, but that seems to do it.
    – Amanda
    Jan 20, 2016 at 18:18
3

You can used fixed positioning if you want the slides to stay in the same place as you scroll. But if you want them to stay at the top you need to use absolute positioning.

.slides {
    position: absolute;
    top: 0;
    left: 0;
}

This will set the div at the 0th pixel from the top and the 0th pixel from the left. Obviously, if you want some separation you can change these numbers.

2
  • That doesn't seem to do it, unfortunately. Nothing shows up. Simple demo at jsfiddle.net/x2neT/1
    – Amanda
    Mar 17, 2014 at 17:37
  • Reveal.js is affecting your section code... not sure where. I'd have to read into the source code. I can't adjust the height width, or anything for the sections. Only the colors. This is why hand-coding these kind of animations can be more useful. At the end of the day, you know what is written and what is affecting what. If you are dead-set on using reveal.js, github.com/hakimel/reveal.js/blob/master/css/reveal.css you will have to change the styles.
    – tywalker
    Mar 17, 2014 at 20:13
2

A little difficult to figure out without some code to work with but this comes to mind. Hope it helps. Ans correct me if I'm going the wrong way

var d = document.getElementById('slides');
   d.style.position = "absolute";
   d.style.left = "230px";
   d.style.top = "207px";

EDITED FIDDLE

This puts it on the top-left, however, after the screen decreases a certain size, it does shift. But it seems like it's affected by the JSFiddle responsiveness. You may be able to control this with @media (min-width: ###px) But it doesn't change when the screen increases size.

Hope it helped

p.s. the coordinates are absolute placed to jsfiddle window, this may need adjustment when used in real application

4
  • That doesn't seem to do it, unfortunately.
    – Amanda
    Mar 17, 2014 at 16:41
  • ok, I was throwing a stone in the dark without seeing any code. Can you provide a fiddle?
    – LOTUSMS
    Mar 17, 2014 at 16:44
  • jsfiddle.net/x2neT/1 shows the problem; jsfiddle.net/x2neT/3 shows how it breaks with your CSS (or with tywalkers, sadly.)
    – Amanda
    Mar 17, 2014 at 17:36
  • I'm updating my answer
    – LOTUSMS
    Mar 17, 2014 at 18:07
2

As many people using reveal.js, I wanted to reduce the vertical blank space at top of each slides.

The problem, a css style is injected from reveal.js script so using directly css to solve this issue will be a fail as the script will provide these default values.

Indeed for each section tag the script compute and inject the css attribute top. This is done at line 1761 version 3.4.1 .

slide.style.top = Math.max( ( size.height - slide.scrollHeight ) / 2, 0 ) + 'px';

So you have to change the calculus for your expected results. To be at the top most:

slide.style.top = 0;

To reduce the size increase the divisor value (default 2), here i use 3:

slide.style.top = Math.max( ( size.height - slide.scrollHeight ) / 3, 0 ) + 'px';

Good luck

1

I think you can get the slide as far up the page as you want with the CSS below. -5% isn't all the way to the top, but you can use a bigger number if you want it closer.

.reveal p:first-child { margin-top: 0px; }
.reveal .slides > section { padding: 0px; }
.reveal div.slides { position: absolute; top: -5%; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.