You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Jekyll(GitHub Pages)中为博客文章图片添加内边距

Fix Image Padding in Jekyll Blog Posts

Hey there! Let's get that image padding sorted so your blog post text doesn't crowd against your images. Here's exactly what you need to do in your style.scss file:

Option 1: Target Only Blog Post Images (Recommended)

This method ensures you don't accidentally add padding to other images on your site (like your header avatar). Look for the .post CSS block in your file (under the LAYOUT / SECTIONS section) and add an img rule inside it:

.post {
  blockquote {
    margin: 1.8em .8em;
    border-left: 2px solid $gray;
    padding: 0.1em 1em;
    color: $gray;
    font-size: 22px;
    font-style: italic;
  }

  // Add this new rule for post images
  img {
    padding: 15px 0; // Adjust values: use 0 15px for left/right padding, or 15px for all four sides
    box-sizing: border-box; // Optional: prevents padding from making images wider than their container
  }

  .comments {
    margin-top: 10px;
  }
  .read-more {
    text-transform: uppercase;
    font-size: 15px;
  }
}

Option 2: Global Image Padding (Affects All Site Images)

If you want padding on every image across your site (including avatars, icons, etc.), modify the existing img rule in the BASE RULES section:

img {
  max-width: 100%;
  padding: 15px; // Adds padding to all four sides; tweak to your preference
  box-sizing: border-box; // Optional but helpful to keep images within their containers
}

Feel free to adjust the 15px value to match your design—you can use different values for vertical vs horizontal spacing (e.g., 10px 15px for top/bottom and left/right padding).

内容的提问来源于stack exchange,提问作者Matt Sosna

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.12 04:56:54