【问题标题】:Style For Span Class Not Showing Up In Inspector StylesSpan 类的样式未出现在 Inspector 样式中
【发布时间】:2017-04-13 15:29:44
【问题描述】:

我将一个 WordPress 函数 .the_post_thumbnail(). 包装在一个带有“post-image”类的 span 中,如下所示:

  echo "<span class='post-image'>".the_post_thumbnail()."</span>";

我尝试应用的样式是width: 100%,以使图像占据&lt;div&gt; / 容器的100% 宽度。但是在浏览器中检查帖子图像时,没有一个帖子图像继承这种样式。

我的 CSS 很简单:

.post-image {
    width: 100%!important;
}

这是我不知道还能尝试什么的情况。我不想在 reset.css 中进行任何更改,因为这会影响所有其他图像 - 我只是想为博客文章设置图像样式。

【问题讨论】:

  • 这是因为the_post_thumbnail() 已经渲染了图像。您是否尝试过改用get_the_post_thumbnail()

标签: php html css wordpress


【解决方案1】:

试试这个:(不需要echo,这个函数echo`s)

the_post_thumbnail('post-thumbnail');

帖子缩略图被赋予一个类wp-post-image,并且还根据所显示的缩略图的大小获得一个类。您可以使用这些 CSS 选择器设置输出样式:

img.wp-post-image
img.attachment-thumbnail
img.attachment-medium
img.attachment-large
img.attachment-full

您还可以为帖子缩略图提供自己的类。显示带有 post-image 类的帖子缩略图:

the_post_thumbnail('post-thumbnail', ['class' => 'post-image']);

样式:

img.post-image {
    width: 100%;
}

【讨论】:

    【解决方案2】:

    尝试使用clear css 属性。 https://developer.mozilla.org/en/docs/Web/CSS/clear

    【讨论】:

      猜你喜欢
      • 2011-09-25
      • 2022-07-25
      • 2019-02-10
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 1970-01-01
      • 2020-07-06
      • 1970-01-01
      相关资源
      最近更新 更多