【发布时间】:2019-09-27 08:13:04
【问题描述】:
我有一个活动信息页面,我从我的表中检索了标签数据。 但是
我无法一一显示标签。
我需要任何 Javascript 吗? 如果我需要,
我非常喜欢使用原生 Javascript
,不是jquery之类的select2插件。
我尝试了多种 CSS 方式,但所有标签都出现在 w3-tag 类中。
show.blade.php
<div class="tag-group">
Tags: <span class="w3-tag">
@foreach($post->tags as $tag) {{ $tag->name }} @endforeach
</span>
</div>
main-info.css
.tag-group {
margin-top: 1rem;
color: white;
margin-bottom: 2px;
}
.w3-tag {
font-size: 14px;
margin-top: 5px;
margin-left: 0.5rem;
padding: 3px;
color: white;
background-color: #626263;
border-radius: 6px;
text-align: center;
}
【问题讨论】:
-
您的问题到底是什么?只是循环的结果显示在单个 HTML 标记中?你应该在循环内写你的
span标签。@foreach($post->tags as $tag) <span class="w3-tag">{{ $tag->name }}</span> @endforeach -
你正在打印w3-tag下的所有标签,所以它是在同一个类下打印,你想实现什么?
标签: javascript php css laravel tags