【问题标题】:Display large image in Rmarkdown在 Rmarkdown 中显示大图
【发布时间】:2021-04-26 17:26:06
【问题描述】:

我正在尝试在 Rmarkdown html 输出中显示一个大图像,而不自动调整它的大小。为此,我想将图像放在可以沿 x 轴和 y 轴滚动的 div 元素(比图像本身小)中。

这是我迄今为止尝试过的:

---
title: "test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

<style>
  .container {
    overflow: scroll !important;
    white-space: nowrap;
    max-width: 300px;
    max-height: 300px;
  }
</style>

<div class="container">
  <img src="https://images.hdqwalls.com/wallpapers/talking-to-the-moon-ym.jpg" width="2000px"/>
</div>

我想要的是能够以原始大小显示图像,并沿两个轴滚动元素。


编辑

这是我正在寻找的插图:

【问题讨论】:

  • 你可能想看看JQuery函数here。图像应“以其原始大小显示,沿两个轴具有可滚动元素”。
  • 感谢您的参考,但这并不是我想要的。
  • 如果我正确理解您的问题,也许您只需要在&lt;style&gt; 中添加img {max-width: 1000%;}
  • @RadovanMiletić 似乎不起作用。没有任何变化。

标签: html css r-markdown


【解决方案1】:

嗯...当我运行 (Knit) 以下代码时:

---
title: "test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

<style>
  .container {
    overflow: scroll !important;
    white-space: nowrap;
    max-width: 300px;
    max-height: 300px;
  }
  img {
    max-width: 1000%;
  }
</style>

<div class="container">
  <img src="https://images.hdqwalls.com/wallpapers/talking-to-the-moon-ym.jpg" width="2000px"/>
</div>

这是我得到的输出:

【讨论】:

  • 有效!不知道我在您的评论中测试代码时发生了什么,我一定是打错了什么。谢谢。
【解决方案2】:

这个怎么样?

---
title: "test"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

<style>
  .container {
    overflow: scroll !important;
    white-space: nowrap;
    width: 100%;
    height: 100%;
  }
</style>

<div class="container">
  <img src="https://images.hdqwalls.com/wallpapers/talking-to-the-moon-ym.jpg"     width="2000px"/>
</div>

不知道这是否可能被忽略,只做width = 100%height = 100%

【讨论】:

  • 感谢您的建议。不幸的是,这不起作用。调整图像大小以适合div
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-25
  • 2021-07-02
  • 1970-01-01
  • 2015-01-09
  • 2020-06-26
  • 1970-01-01
相关资源
最近更新 更多