如何在Jekyll中增加图片周围的填充。

3
我有一个使用GitHub Pages的Jekyll博客,其中一些博客文章中嵌入的图片没有任何填充,导致文字与图片之间过于接近:

enter image description here

我希望在style.scss文件中指定填充,以便将来应用于博客文章中的所有图像。我应该在哪里添加padding参数?谢谢!
---
---

//
// IMPORTS
//

@import "reset";
@import "variables";
// Syntax highlighting @import is at the bottom of this file

/**************/
/* BASE RULES */
/**************/

html {
  font-size: 100%;
}

body {
    background: $white;
  font: 16px/1.4 $helvetica;
  color: $darkGray;
}

.container {
  margin: 0 auto;
  max-width: 740px;
  padding: 0 10px;
  width: 100%;
}

h1, h2, h3, h4, h5, h6 {
  font-family: $helveticaNeue;
  color: $darkerGray;
  font-weight: bold;

  line-height: 1.7;
  margin: 1em 0 15px;
  padding: 0;

  @include mobile {
    line-height: 1.4;
  }
}

h1 {
  font-size: 30px;
  a {
    color: inherit;
  }
}

h2 {
  font-size: 24px;
}

h3 {
  font-size: 20px;
}

h4 {
  font-size: 18px;
  color: $gray;
}

p {
  margin: 15px 0;
  text-align: justify;
}

a {
  color: $blue;
  text-decoration: none;
    cursor: pointer;
  &:hover, &:active {
    color: $blue;
  }
}

ul, ol {
  margin: 15px 0;
  padding-left: 30px;
}

ul {
  list-style-type: disc;
}

ol {
  list-style-type: decimal;
}

ol ul, ul ol, ul ul, ol ol {
  margin: 0;
}

ul ul, ol ul {
  list-style-type: circle;
}

em, i {
  font-style: italic;
}

strong, b {
  font-weight: bold;
}

img {
  max-width: 100%;
}

// Fixes images in popup boxes from Google Translate
.gmnoprint img {
  max-width: none;
}

.date {
  font-style: italic;
  color: $gray;
}

// Specify the color of the selection
::-moz-selection {
  color: $black;
  background: $lightGray;
}
::selection {
  color: $black;
  background: $lightGray;
}

// Nicolas Gallagher's micro clearfix hack
// http://nicolasgallagher.com/micro-clearfix-hack/
.clearfix:before,
.clearfix:after {
    content: " ";
    display: table;
}

.clearfix:after {
    clear: both;
}

/*********************/
/* LAYOUT / SECTIONS */
/*********************/

//
// .masthead
//

.wrapper-masthead {
  margin-bottom: 50px;
}

.masthead {
  padding: 20px 0;
  border-bottom: 1px solid $lightGray;

  @include mobile {
    text-align: center;
  }
}

.site-avatar {
  float: left;
  width: 70px;
  height: 70px;
  margin-right: 15px;

  @include mobile {
    float: none;
    display: block;
    margin: 0 auto;
  }

  img {
    border-radius: 5px;
  }
}

.site-info {
  float: left;

  @include mobile {
    float: none;
    display: block;
    margin: 0 auto;
  }
}

.site-name {
  margin: 0;
  color: $darkGray;
  cursor: pointer;
  font-family: $helveticaNeue;
  font-weight: 300;
  font-size: 28px;
  letter-spacing: 1px;
}

.site-description {
  margin: -5px 0 0 0;
  color: $gray;
  font-size: 16px;

  @include mobile {
    margin: 3px 0;
  }
}

nav {
  float: right;
  margin-top: 23px; // @TODO: Vertically middle align
  font-family: $helveticaNeue;
  font-size: 18px;

  @include mobile {
    float: none;
    margin-top: 9px;
    display: block;
    font-size: 16px;
  }

  a {
    margin-left: 20px;
    color: $darkGray;
    text-align: right;
    font-weight: 300;
    letter-spacing: 1px;

    @include mobile {
      margin: 0 10px;
      color: $blue;
    }
  }
}

//
// .main
//

.posts > .post {
  padding-bottom: 2em;
  border-bottom: 1px solid $lightGray;
}

.posts > .post:last-child {
  padding-bottom: 1em;
  border-bottom: none;
}

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

  .comments {
    margin-top: 10px;
  }

  .read-more {
    text-transform: uppercase;
    font-size: 15px;
  }

}

.wrapper-footer {
  margin-top: 50px;
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  background-color: $lightGray;
}

footer {
  padding: 20px 0;
  text-align: center;
}

// Settled on moving the import of syntax highlighting to the bottom of the CSS
// ... Otherwise it really bloats up the top of the CSS file and makes it difficult to find the start
@import "highlights";
@import "svg-icons";

你能提供正在运行的代码的链接吗? - Andy Hoffman
@AndyHoffman 是的,刚刚编辑了一下,包括了代码。谢谢。 - Matt Sosna
我想看一个真实的例子,可以在浏览器的开发者工具中进行测试和检查。 - Andy Hoffman
1个回答

2
我会修改您在style.scss中的img标签...
将此更改为...
"最初的回答"
img {
  max-width: 100%;
}

to this...

img {
  max-width: 100%;
  padding: 5px;
}

如果图像有自己的DIV,请使用以下代码... 最初的回答。
.imageDiv img {
  padding: 5px;
}

这会为整个网站上的每张图片添加 padding: 5px。这就是我的想法要查看实际网站,以创建一个更具体规则的原因。 - Andy Hoffman
我写了,我想在将来将所有博客文章中的图片应用填充,这就是为什么我认为style.scss是这里要走的路。该网站仍处于建设阶段。 - Matt Sosna
啊,是的。这些图片在哪个div里?在CSS文件中,在img标签之前添加那个div。我已经编辑了上面的内容作为示例。 - Graphics Factory

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接