You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel:如何修改仪表盘问候语div的字体样式与底部间距?

解决方案

先纠正你之前的几个错误点

  1. public_path() 不能用于前端路径:这是Laravel后端的服务器绝对路径函数,浏览器无法识别,必须用 asset() 生成前端可访问的URL。
  2. @font-face 不需要闭合标签:语法就是 @font-face { ... },IDE识别问题不影响实际运行。
  3. HTML没有 font-size 属性:要设置字体大小,必须用 style 属性或CSS类,不能直接写在标签上。

方法1:快速内联样式实现(适合临时调试)

在页面的 <head> 部分先正确引入自定义字体,然后给问候语div加内联样式:

<head>
    <!-- 其他head内容 -->
    @isset($user)
    <style>
        @font-face {
            font-family: 'Muli-Bold';
            src: url('{{ asset('fonts/materialdesignicons-webfont.ttf') }}') format('truetype');
            font-weight: bold;
            font-style: normal;
        }
    </style>
    @endisset
</head>

<body>
    <!-- 问候语div -->
    <div style="font-size: 28px; font-family: 'Muli-Bold', sans-serif; margin-bottom: 20px;">
        @isset($user)
            Hallo {{ $user->name }},
        @endisset
    </div>

    <!-- 后续内容 -->
    <div>Willkommen im  <b class="text-gray-700">Formular-Editor!</b></div>
    <div>Neue Formulare kannst du über den Tab <i><b class="text-gray-700">"Editor"</b></i> oben in der Leiste anlegen. Hier kannst Du auch bestehende Formulare bearbeiten.</div>
</body>

方法2:用CSS类实现(规范复用)

  1. 在项目的CSS文件(比如 resources/css/app.css)中添加样式:
/* 自定义字体 */
@font-face {
    font-family: 'Muli-Bold';
    src: url('/fonts/materialdesignicons-webfont.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}

/* 问候语样式类 */
.dashboard-greeting {
    font-size: 28px;
    font-family: 'Muli-Bold', sans-serif;
    margin-bottom: 20px;
}
  1. 编译CSS(如果用Vite,执行 npm run dev),然后在blade模板中使用类:
<div class="dashboard-greeting">
    @isset($user)
        Hallo {{ $user->name }},
    @endisset
</div>

<!-- 后续内容保持不变 -->

方法3:用Tailwind CSS实现(如果项目已使用)

看你的代码里有 text-gray-700,推测项目用了Tailwind,可直接用内置类+自定义字体:

  1. 在 tailwind.config.js 中配置自定义字体:
module.exports = {
    theme: {
        extend: {
            fontFamily: {
                'muli-bold': ['Muli-Bold', 'sans-serif'],
            },
        },
    }
}
  1. 在页面 <head> 引入字体:
<style>
    @font-face {
        font-family: 'Muli-Bold';
        src: url('{{ asset('fonts/materialdesignicons-webfont.ttf') }}') format('truetype');
        font-weight: bold;
        font-style: normal;
        font-display: swap;
    }
</style>
  1. 使用Tailwind类:
<div class="text-2xl md:text-3xl font-muli-bold mb-6">
    @isset($user)
        Hallo {{ $user->name }},
    @endisset
</div>

内容的提问来源于stack exchange,提问作者TraktorJack

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 06:31:21