Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 替换<;李>;在各自的帖子中指定图像_Html_Css_Hugo_Blogdown - Fatal编程技术网

Html 替换<;李>;在各自的帖子中指定图像

Html 替换<;李>;在各自的帖子中指定图像,html,css,hugo,blogdown,Html,Css,Hugo,Blogdown,我有一个html列表元素,它将博客文章呈现为列表 <ul class="posts"> {{ range .Data.Pages -}} <li> <span class="postlist_container"> <a href="{{ .Permalink }}">{{ .Title }}</a> <time class="pull-right post-list" datetime="{{

我有一个html列表元素,它将博客文章呈现为列表

<ul class="posts">
{{ range .Data.Pages -}}
  <li>
    <span class="postlist_container">
      <a href="{{ .Permalink }}">{{ .Title }}</a> 
    <time class="pull-right post-list" datetime="{{ .Date.Format "2006-01-02T15:04:05Z0700" }}">{{ .Date.Format "Mon, Jan 2, 2006" }}</time> </span>
  </li>
{{- end }}
</ul>
我通过在列表中添加一个标记,成功地将图像与文章标题一起呈现

---
thumbnail: "/post/source/image_tn.jpg"
---
<img src="{{ with .Params.thumbnail }}{{ . }}{{ end }}">
是否有方法引用标记文件中Param.缩略图中的图像

这不起作用:

.posts {
  list-style-image: url("{{ with .Params.thumbnail }}{{ . }}{{ end }}");
}

任何帮助都将不胜感激。

与其使用
列表样式图像,不如使用其中一个伪元素?像这样

li{
  position: relative;
  padding-left: 5px;
}

li::before{
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  background: url("{{ with .Params.thumbnail }}{{ . }}{{ end }}") no-repeat center center;
}

希望这有帮助。

要使CSS样式表使用标记,您需要将其包含在HTML模板中

在模板中插入一次您想要动态更新的规则(最好是在
中插入,但其他任何地方都可以

<style>
.posts {
  list-style-image: url("{{ with .Params.thumbnail }}{{ . }}{{ end }}");
}
</style>

您的样式表未被解析,路径应该是纯写的,或者在文档中的标记之间包含此规则,以便更新路径。syntax
{{}
仅在模板中工作,CSS文件不是模板的一部分,因此不会动态重写路径。如果使用背景或列表样式图像…图像不会自动替换项目符号。Set
li{list style:none;}
这是一个可以接受的解决方法。非常感谢您的帮助!将
li
设置为
display:flex
img
a
标记将成为flex项并放在一行中。然后您可以使用
justify content
属性来确定它们之间的间距,效果非常好。感谢您的帮助@NimsrulesThank您指出了这个选项。很高兴知道syntax
{}
在css中不起作用。需要报告的一件事是,只有当我将syle标记放入
  • 中时,它才起作用。然而,我随后意识到用图像替换项目符号有点难以正确对齐,因此我选择删除项目符号并在一行中显示元素。
    <style>
    .posts {
      list-style-image: url("{{ with .Params.thumbnail }}{{ . }}{{ end }}");
    }
    </style>
    
    <img src="{{ with .Params.thumbnail }}{{ . }}{{ end }}">
    
    <style>
    .posts {
      list-style-image: url("{{ with .Params.thumbnail }}{{ . }}{{ end }}");
    }
    </style>