【问题标题】:Laravel Blade components and slots: slot content not displayed beside each otherLaravel Blade 组件和插槽:插槽内容不并排显示
【发布时间】:2020-12-11 17:37:27
【问题描述】:

我正在使用刀片组件,并且我有一个带有两个插槽的组件。我想将图像传递给第一个插槽,将文本传递给第二个。它们应该并排显示,但它们显示在不同的行中。

插槽的代码 sn-p:

<h1>
    {{ $icon }} {{ $title }}
</h1>

填充槽的代码sn-p:

@component('components.pageheader')
       @slot('icon')
            <img src="{{ asset('img/an_image.png') }}" width="28px" height="28px">
       @endslot
       @slot('title')
            myTitle
       @endslot
@endcomponent

我错过了什么?

【问题讨论】:

  • 在&lt;img&gt; 标签上尝试style="display:inline-block; margin-right:10px;"
  • 谢谢!它有效。我将 标签放在
  • 已按照建议发布为答案,以便后续访问者受益

标签: laravel laravel-blade


【解决方案1】:

尝试在包装器 div 上为 img 设置 display:inline-block,如下所示

@component('components.pageheader')
       @slot('icon')
            <div style="display:inline-block; margin-right:10px">
                <img src="{{ asset('img/an_image.png') }}" width="28px" height="28px">
            </div>
       @endslot
       @slot('title')
            myTitle
       @endslot
@endcomponent

【讨论】:

    猜你喜欢
    相关资源
    最近更新 更多
    热门标签