Laravel背景图片只在登录页面上

问题描述 投票:1回答:3

我在Laravel 5.4项目上工作,我想要一个login.blade.php的背景图像,而不是home.blade.php或其他网站。

如果我在所有页面上更改Body背景,那么最好只在登录页面上执行此操作?

谢谢

php css laravel-5
3个回答
1
投票

如果您在登录页面中,请将课程添加到您的身体

<body class="{{ Request::path() == 'login' ? 'background-image' : '' }}"></body>

而不是为课程添加CSS

.background-image{
    //your code for background image set
}

0
投票

以下是一些选项:

  1. 创建一个<script type="text/javascript"> document.body.style.backgroundImage = "url('img_tree.png')"; </script>并将其放在login.blade.php中。这是一个快速但糟糕的计划。
  2. 使用刀片部分(https://laravel.com/docs/5.4/blade)!在layouts / app.blade.php中创建body标签,如下所示: <body @section('body-changes', '')> 在你的login.blade.php中: @section('body-changes') style='background-color: red;' @endsection
  3. 最好的方法:创建一个包含所有其他样式的部分,比如@section('styles', ''),然后将它放在layouts / app.blade.html中的</body>之前,然后每当你想为你的页面创建额外的样式时 @section('styles') <style type='text/css'> your-css-here </style> @endsection

0
投票

您可以查看要求的路线

<body class="{{ Request::is('/login') ? 'image' : '' }}">

然后是以下css

body.image {

}

更简单,更清洁的方法是使用laravelista的Ekko包。它为活动路由和活动URL提供支持。

© www.soinside.com 2019 - 2024. All rights reserved.