3

I am using reveal-md to render a two-column slide with code and an image, taking inspiration from How to use two-column layout with reveal.js?.

A reproducible example is:

---
title: "Bad two-columns rendering"
author: "Yours truly"
---

![tux](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Tux-simple.svg/768px-Tux-simple.svg.png) <!-- .element: style="float: right; width: 50%" -->

```python

print("Is the rendering bad?")
print("Yeah!")
print("How can you be sure?")
print("Look at the beak of Tux")

```
<!-- .element: style="width: 50%" -->

Once rendered, I get

enter image description here

If you look attentively, you can see that the "code box" overextends to the right and overlaps with the image (see the red highlighting)

enter image description here

Does anyone know how to fix this directly in the source (markdown) code? It's a not-so-minor annoyance. I tried fiddling with the markdown above but to no avail.

Davide Fiocco
  • 5,350
  • 5
  • 35
  • 72

2 Answers2

2

Another way to do it by using a little more modern CSS attribute called flex. I think your problems resulting in some wired template settings of the environment you are using. So here is my second go:

--
title: "Bad two-columns rendering"
author: "Yours truly"
---
<style>
.container{
    display: flex;
}
.col{
    flex: 1;
}
</style>

<div class="container">

<div class="col">

```python

print("Is the rendering bad?")
print("Yeah!")
print("How can you be sure?")
print("Look at the beak of Tux")

```
<!-- .element: style="width: 100%;" -->

</div>

<div class="col">

![tux](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Tux-simple.svg/768px-Tux-simple.svg.png)

</div>

</div>

Here I'm using classes to set the CSS attributes.

example screenshot

wittich
  • 2,079
  • 2
  • 27
  • 50
  • The best way to debug it is over the [Developer Console](https://developers.google.com/web/tools/chrome-devtools/open) of your browser (eg. Chrome). Make sure the source code did what it supposed to do... I update my answer. – wittich Aug 14 '20 at 19:26
1

As you're working with float elements you should float both elements and change their order

.element {
    float: left;
    width: 50%;
}

The whole example would look like that:

--
title: "Bad two-columns rendering"
author: "Yours truly"
---

```python

print("Is the rendering bad?")
print("Yeah!")
print("How can you be sure?")
print("Look at the beak of Tux")

```
<!-- .element: style="float: left; width: 50%;" -->

![tux](https://upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Tux-simple.svg/768px-Tux-simple.svg.png)
<!-- .element: style="float: left; width: 50%;" -->

example screenshot


PS: Sometimes it helps to set an element to overflow: hidden;


Debugging:

Make sure that the Source Code looks like that:

<section data-markdown="" data-markdown-parsed="true" 
    style="top: 16.5px; display: block;" class="present">
    <pre style="float: left; width: 50%;"><code class="python hljs">
print(<span class="hljs-string">"Is the rendering bad?"</span>)
print(<span class="hljs-string">"Yeah!"</span>)
print(<span class="hljs-string">"How can you be sure?"</span>)
print(<span class="hljs-string">"Look at the beak of Tux"</span>)
</code></pre><!-- -->

<p style="float: left; width: 50%;">
    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/2/2b/Tux-simple.svg/768px-Tux-simple.svg.png" alt="tux">
</p>
<!-- -->
</section>

You can use your browser Developer Console to do so (eg. Chrome the DevTools)

Davide Fiocco
  • 5,350
  • 5
  • 35
  • 72
wittich
  • 2,079
  • 2
  • 27
  • 50
  • The way I debugged that issue was by using revels.js in docker. Just generate a `slides.md` file eg. in the folder `~/revels-js/` and start the docker container with it: `docker run --rm -p 1948:1948 -v ~/revels-js:/slides webpronl/reveal-md:latest`. The result can be seen and debug in the browser: http://localhost:1948/slides.md – wittich Aug 18 '20 at 18:53