Laravel技巧库

404页面

此课程是收费课程,请先购买或加入会员后再访问。

所谓404,其实就是访问不存在的路径,页面显示的内容。例如我们访问一下/hello,这个路径在路由文件中是没有定义过的,默认显示的样子,实在是有点太一般了。那么我们就自己优化一下他。

课程使用的样式是网上找的 https://codepen.io/heyriad/pen/qHExo

views目录中,新建一个errors目录。里面再建一个404.blade.php

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>404</title>
    <link rel="stylesheet" href="/assets/css/404.css">
</head>
<body>

<div id='error-page'>
    <div id='error-inner'>
        <h1> I told you to text your mom</h1>
        <div class="pesan-eror">404</div>
        <p class="balik-home"><a href="/">Back to Home, your handsome dad here!</a></p><br/>
    </div>
</div>

</body>
</html>

public/assets/css目录中,新建一个404.css

#error-page {
    background-color: #53C1C0;;
    position: fixed !important;
    position: absolute;
    text-align: center;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 99999;
}

#error-inner {
    margin: auto;
}

#error-inner h1 {
    text-transform: uppercase;
    color: white;
    margin-top: 20px;
    font-size: 20px;
}

.pesan-eror {
    width: 200px;
    height: 200px;
    margin: 0 auto 40px;
    background: #ffc754;
    color: #fff;
    font-size: 100px;
    line-height: 200px;
    -moz-border-radius-topleft: 75px;
    -moz-border-radius-topright: 75px;
    -webkit-border-top-left-radius: 75px;
    -webkit-border-top-right-radius: 75px;
    border-top-left-radius: 95px;
    border-top-right-radius: 95px;
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 14px;
    position: relative;
    animation-name: floating;
    -webkit-animation-name: floating;

    animation-duration: 1.5s;
    -webkit-animation-duration: 1.5s;

    animation-iteration-count: infinite;
    -webkit-animation-iteration-count: infinite;
}

@keyframes floating {
    0% {
        transform: translateY(0%);
    }
    50% {
        transform: translateY(8%);
    }
    100% {
        transform: translateY(0%);
    }
}

@-webkit-keyframes floating {
    0% {
        -webkit-transform: translateY(0%);
    }
    50% {
        -webkit-transform: translateY(8%);
    }
    100% {
        -webkit-transform: translateY(0%);
    }
}

.pesan-eror::after {
    content: " ";
    width: 0;
    height: 0;
    bottom: -17px;
    border-color: #ffc754 transparent transparent;
    border-style: solid;
    border-width: 20px 20px 0;
    position: absolute;
    left: 40%;
}

.balik-home {
    position: relative;
    margin: 20px auto;
    display: block;
    padding: 10px 15px 10px 15px;
    font-family: "Helvetica Neue", Helvetica;
    font-size: 30px;
    background: #f26964;
    border: 0;
    color: #fff;
    border-radius: 3px;
    outline: none;
    width: 600px;
    height: 40px;
    cursor: pointer;

}

.balik-home:hover {
    background: none;
}

.balik-home:after, .balik-home:before {
    position: absolute;
    background: #285677;
    content: "";
    width: 0%;
    height: 100%;
    bottom: 0px;
    left: 0;
    z-index: -999999999;
    border-radius: 3px;
}

.balik-home:before {
    background: #f26964;
    width: 100%;
}

.balik-home:hover:after {
    width: 100%;
    -webkit-transition: all 1s ease-in-out;
    -moz-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out;
}

.balik-home a {
    color: white;
    text-decoration: none
}

好了,就这么的简单,404页面就做出去了,当用户在访问一些不存在的路径是,就会自动的显示出这个页面来。