Obsidian插入图片分列显示

1.下载安装Contextual Typography的最新版本

2.复制以下代码,改文件后缀为 .css 或者直接从插入图片分列下载

/* This snippet requires Contextual Typography 2.2.1+ */
/* https://github.com/mgmeyers/obsidian-contextual-typography */

:root {
  --content-base-width: 45rem;
}

/* ----------------------------------------- */
/* Handle overall content width */
/* ----------------------------------------- */

/* Wrapper with padding keeps content from bumping the edges */
.markdown-preview-view.is-readable-line-width {
  padding-inline: 30px;
}

/* Container controlling overall max content width */
.markdown-preview-view.is-readable-line-width .markdown-preview-section {
  width: 100%;
  max-width: var(--content-max-width, 45rem); /* Second value is fallback in case user isn't using Style settings */
}

/* All children of overall container are divs */
.markdown-preview-view.is-readable-line-width .markdown-preview-section > div {
  margin-inline: auto;
  width: min(var(--content-base-width), 100%);
}

/* Specific children of overall container that contain media */
.markdown-preview-view.is-readable-line-width .markdown-preview-section div[data-is-embed] {
  width: 100%;
}

/* ----------------------------------------- */
/* Make media items display in rows */
/* ----------------------------------------- */

/* p tags wrap each row */
.markdown-preview-view.is-readable-line-width .markdown-preview-section div[data-is-embed] > p {
  display:grid;
  grid-template-columns:repeat(auto-fit, minmax(0, 1fr));
  grid-gap: var(--media-grid-gap, 7px);
  margin: 0;
}

/* Remove breaks from the document flow */
.markdown-preview-view.is-readable-line-width .markdown-preview-section div[data-is-embed] > p br {
  display: none;
}

/* Media items sourced from your vault are wrapped in a span – media linked from the web is not wrapped */
.markdown-preview-view.is-readable-line-width .markdown-preview-section div[data-is-embed] > p > span {
  display: flex;
}

/* Apply this to all img/video tags in a row whether they're wrapped in a span or not */
.markdown-preview-view.is-readable-line-width .markdown-preview-section div[data-is-embed] > p img,
.markdown-preview-view.is-readable-line-width .markdown-preview-section div[data-is-embed] > p video {
  flex: 1;
  align-self: stretch;
  object-fit: cover;
  border-radius: var(--media-border-radius, 4px);
}

/* Create gaps between rows */
.markdown-preview-view.is-readable-line-width .markdown-preview-section div[data-is-embed] + div[data-is-embed] {
  margin-top: var(--media-grid-gap, 7px);
}

/* ----------------------------------------- */
/* Style settings */
/* ----------------------------------------- */

/* @settings
name: Media Grid Snippet
id: media-grid-snippet
settings:
  -
      id: content-max-width
      title: Grid width
      description: Set the max width of your grid layouts.
      type: variable-select
      allowEmpty: false
      default: var(--content-base-width)
      options:
          - 
              label: Base width
              value: var(--content-base-width)
          - 
              label: Small
              value: calc(var(--content-base-width) + 5%)
          - 
              label: Medium
              value: calc(var(--content-base-width) + 10%)
          - 
              label: Large
              value: calc(var(--content-base-width) + 20%)
          - 
              label: Full width
              value: 100%
  -
      id: media-grid-gap
      title: Grid gap
      description: Set the gap size between items in your grid layouts.
      type: variable-number-slider
      format: px
      default: 7
      min: 0
      max: 80
      step: 1
  -
      id: media-border-radius
      title: Border radius
      description: Set the border radius of your images and videos.
      type: variable-number-slider
      format: px
      default: 4
      min: 0
      max: 40
      step: 1
*/

3.在设置中选择外观,拉到最底部 css 代码片段选项,点击文件夹图标选择第二步中创建的 .css 文件,点击文件夹图标旁边的更新图标,更新。


4.打开第二步中 .css 文件的按钮,完成。

5.图片插入示例:插入的图片链接两行之间不要空行,自动实现图片分列效果

6.效果

原教程地址:
Obsidian插入图片分列
参考教程:
Obsidian 图片分列显示

4 个赞

失败。不知道为啥,还是一如既往地竖排显示。

切换一下视图,是在阅读视图里才能分列

还需要 front-matter 区写上 cssclass: img-grid才成功。

我发的这个教程不需要,按底下参考教程里那么设置才需要。

为什么,我按照你这个设置了,预览模式下还是不能分列啊?可否给看看啥问题?





这该打开的按钮也都打开了,就是不知道怎么弄都不能分列

你看看你插入的图片链接之间有空行吗?要是有的话删掉试试

image
我刚看了下,没有空格,应用图片的方式试了两种代码都不行,搞不懂了

搞了半天无意中解决,添加的图片链接前面不能有不换行的文字,如果文字后放链接,要回车两次换行隔开

还不够傻瓜化,期待更好的插件

给图片加了备注后不能并列显示,把备注删了就可以了

把图片放在表格里应该可以实现吧。