Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large images dangling off screen #1099

Open
tsdmgz opened this issue Jan 11, 2015 · 19 comments
Open

Large images dangling off screen #1099

tsdmgz opened this issue Jan 11, 2015 · 19 comments

Comments

@tsdmgz
Copy link

tsdmgz commented Jan 11, 2015

openSUSE 13.2 x86_64 3.16.7-7-desktop
tested on Firefox 34.0.5, Chromium 39.0.2171.65
working on Konqueror 4.14.3

Large-ish images are rendered with bottom part off screen. Current resolution is 1600x900. Portrait orientations seem to work properly.

This is the image used
sample

Screenshot in FF 34
screenshot

Same slide in Konqueror (WebKit based?)
konqueror

@tsdmgz
Copy link
Author

tsdmgz commented Jan 19, 2015

After a bit of fiddling, it apparently has something to do with max-height, but I can't exactly figure out what it is.
Adding style="height:65%" or some other size to <img> seems to work around, but it has to be added for every <img> tag. Interestingly enough, portrait resolutions seem to display correctly. Looks like tall images are mainly affected.

@Mark-L6n
Copy link

Mark-L6n commented Mar 4, 2015

I fixed this with class="stretch" (see https://github.com/hakimel/reveal.js/#user-content-stretching-elements )
By the way, I found this did not work if in Reveal.initialize you have width or height set to a percentage, as in:
width: "80%",
height: "80%",

@tsdmgz
Copy link
Author

tsdmgz commented Mar 5, 2015 via email

@Mark-L6n
Copy link

The images didn't fill the screen correctly (can't remember if they were too large or too small).

@tsdmgz
Copy link
Author

tsdmgz commented Mar 10, 2015 via email

@sedrubal
Copy link

I could resolve this issue by adding this css:

.reveal section.img_container {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
}
.reveal section img {
        display: block;
        margin: auto;
        height: auto;
        max-height: 100%;
        width: auto;
        max-width: 100%;
}

and by adding class="img_container" to all sections containing only <img>...

I don't know if this is a good solution...

@vanquang9387
Copy link

class="stretch" seems to only work at first section in a group of vertical sections.

@adalmieres
Copy link

I hit the same problem with a large square image, with or without class="stretch". The image is placed in a section just after a vertical of tree sections.
It seems that the horizontal visibility is prevalent to the vertical visibility.

@odkr
Copy link

odkr commented May 11, 2018

I had the same problem and could solve it by:

.reveal.reveal img
{
    border: none;
    box-shadow: none;
    max-height: calc(66vh);
    max-width: calc(66vw);
}

@Jmuccigr
Copy link
Contributor

Here's what I ended up with in my scss file (see #2127). It creates a format in which figures are expanded to full screen and their captions are invisible until hovered over. I use it for classroom lectures in which I frequently want to show just an image:

// Trying to get full-screen images

.reveal figure, .reveal section {
    height:  inherit;
}

//1. Make canvas bigger. See https://github.com/hakimel/reveal.js/issues/638
.reveal .slides {
	width: 100%;
	height: 100%;
	top: 0;
	margin-top: 0;
}

//2. Remove padding so images reach top & bottom edges
.reveal .slides section,
.reveal .slides section > section {
  padding: 0;
}

.reveal section img {
  border: none;
  margin: 0;
}

.reveal img, .reveal video, .reveal iframe {
  max-height: 100%;
  height: 100%;
}

//3. Wide image that always fits
.reveal figure img {
  box-shadow: none;
  max-width: 100%;
  object-fit: contain;
}

//4. Hide caption. Show on top of image via hover.
.reveal figcaption {
	display: block;
	position: absolute;
	margin: auto;
	width: 96%;
	left: 0;
	text-align: center;
	bottom: 1em;
	height: auto;
	background-color: white;
	color: black;
	font-size: smaller;
	padding-left: 2%;
	padding-right: 2%;
	opacity: 0;
}

.reveal figcaption:hover {
  opacity: .9;
}

@davidjb
Copy link
Contributor

davidjb commented Aug 19, 2018

If using Markdown to render images, even adding the CSS like so:

![Example](img/example.png) <!-- .element class="stretch" -->

isn't enough because when rendered, the Markdown renderer adds a <p> tag around the <img> which presents the stretch code from applying. The current codebase is looking for just section > .stretch, which means this won't work. I worked around the issue by editing the reveal.js source so that it applies like so:

toArray( dom.slides.querySelectorAll( 'section > .stretch, section > p > .stretch' ) ).forEach( function( element ) {

Getting rid of the surrounding <p> tag would be better, but I haven't seen if that's possible.

@codecounselor
Copy link

codecounselor commented Nov 25, 2018

I ran into the same problem @davidjb describes, and I solved it by just putting HTML in my markdown. It's gross, but appears to be working.

## Heading
<p class="stretch"><img src="https://someurl"></p>

@tribbloid
Copy link

tribbloid commented Feb 13, 2019

also affects me.

For jupyter nbconvert everything fails, the image generated by matplotlib cannot use any styling

@AtomicNess123
Copy link

Here's what I ended up with in my scss file (see #2127). It creates a format in which figures are expanded to full screen and their captions are invisible until hovered over. I use it for classroom lectures in which I frequently want to show just an image:

// Trying to get full-screen images

.reveal figure, .reveal section {
    height:  inherit;
}

//1. Make canvas bigger. See https://github.com/hakimel/reveal.js/issues/638
.reveal .slides {
	width: 100%;
	height: 100%;
	top: 0;
	margin-top: 0;
}

//2. Remove padding so images reach top & bottom edges
.reveal .slides section,
.reveal .slides section > section {
  padding: 0;
}

.reveal section img {
  border: none;
  margin: 0;
}

.reveal img, .reveal video, .reveal iframe {
  max-height: 100%;
  height: 100%;
}

//3. Wide image that always fits
.reveal figure img {
  box-shadow: none;
  max-width: 100%;
  object-fit: contain;
}

//4. Hide caption. Show on top of image via hover.
.reveal figcaption {
	display: block;
	position: absolute;
	margin: auto;
	width: 96%;
	left: 0;
	text-align: center;
	bottom: 1em;
	height: auto;
	background-color: white;
	color: black;
	font-size: smaller;
	padding-left: 2%;
	padding-right: 2%;
	opacity: 0;
}

.reveal figcaption:hover {
  opacity: .9;
}

I'm a newbie in reveal.js. Where exactly shall I save this code? I am using Jupyter Notebook to create slides, but the images are out of bound.

geyuqiu added a commit to geyuqiu/presentations that referenced this issue Sep 12, 2021
@tillmariajuergens
Copy link

If using Markdown to render images, even adding the CSS like so:

![Example](img/example.png) <!-- .element class="stretch" -->

isn't enough because when rendered, the Markdown renderer adds a <p> tag around the <img> which presents the stretch code from applying. The current codebase is looking for just section > .stretch, which means this won't work. I worked around the issue by editing the reveal.js source so that it applies like so:

toArray( dom.slides.querySelectorAll( 'section > .stretch, section > p > .stretch' ) ).forEach( function( element ) {

Getting rid of the surrounding <p> tag would be better, but I haven't seen if that's possible.

I could only solve it with this hotfix at the end of a presentation html, which removes the wrapping <p> tag

<script>
	const allStretchedImages = document.getElementsByClassName("r-stretch"); // or "stretch"
	allStretchedImages.forEach( function( image ) {
		parent = image.parentNode;
		if ( parent.nodeName && parent.nodeName.toLowerCase() === 'p' ) {
			var fragment = document.createDocumentFragment();
			while( parent.firstChild ) {
				fragment.appendChild( parent.firstChild );
			}
			parent.parentNode.replaceChild( fragment, parent );
		}
	} );
</script>

Would be helpful, if it would be part of reveal.js, or am I wrong?

@prologic
Copy link

prologic commented May 9, 2023

Is there a proper fix for this that makes images fit, even for Markdown image links?

@jaegermoritz
Copy link

jaegermoritz commented May 17, 2023

I don't know it sth. changed in the meantime, but for me the following solution does the trick using a separate .md-file:

![book in library](assets/introduction/image1.jpg)

<!-- .element: class="r-stretch" -->

Some more descriptive text below the image

I've put the HTML comment section below the markdown link. Then the auto adjustment of Stretch applies to the p-tag, which is always wrapped around. As the image within that p-tag is responsive by default it's getting resized. And finally my text below the image is visible ;)

@GlenRosales
Copy link

GlenRosales commented May 20, 2023 via email

@prologic
Copy link

@jaegermoritz 's comment works.

Example Markdown slide:

## Title

- Some content
- ..

![](./images/image.png)
<!-- .element: class="r-stretch" -->

---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests