Semi Login Page : CSS version

DATE : 2023/10/28

์ด๋ฒˆ์—๋Š” CSS๋กœ ์Šคํƒ€์ผ์„ ์ž…ํžŒ Login page๋ฅผ ๋งŒ๋“ค์–ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค!

(bootstrap๊ณผ๋Š” ๋‹ฌ๋ฆฌ CSS๋Š” ๋ชจ๋“  ์ฝ”๋“œ๋ฅผ ์ง์ ‘ ์ž‘์„ฑํ–ˆ๋‹ค)

์ฝ”๋“œ๋ฅผ ์‚ดํŽด๋ณด๊ธฐ ์ „, ์™„์„ฑ๋œ ๋ชจ์Šต๋ถ€ํ„ฐ ๋ณด๊ณ  ๊ฐ€์ž.

Semi Login Page : Bootstrap version๊ณผ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ํŽ˜์ด์ง€์—์„œ ์ฒ˜๋ฆฌํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฑด

์‚ฌ์šฉ์ž๊ฐ€ admin:admin1234๋ฅผ ์ž…๋ ฅํ–ˆ์„ ๋•Œ๋งŒ ๋กœ๊ทธ์ธ์„ ํ—ˆ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

๊ทธ๋Ÿผ login page code๋ถ€ํ„ฐ ํ•˜๋‚˜์”ฉ ์‚ดํŽด๋ณด๋„๋ก ํ•˜์ž!


[index.html]

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Page</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <h1>LOGIN</h1>
        <form action="./result.php" method="post">
            <label for="name">Username</label>
            <input type="text" name="name">
            <label for="password">Password</label>
            <input type="password" name="password">
            <button class="login_btn">Log in</button>
        </form>
    </div>
</body>
</html>

index.html์€ ์œ„์—์„œ ํ™•์ธํ•œ ํŽ˜์ด์ง€์˜ ์ฝ”๋“œ์ด๋‹ค.

์ด๋ฒˆ์—๋Š” CSS๋กœ ์Šคํƒ€์ผ์„ ์ž…ํžˆ๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•  style.css ํŒŒ์ผ์„ link tag๋กœ ์—ฐ๊ฒฐํ•ด์ค€๋‹ค.

๋ชจ๋“  tag๋ฅผ ์ œ์ผ ๋ฐ”๊นฅ์—์„œ ๋ฌถ์–ด์ฃผ๋Š” <div> tag ์•ˆ์œผ๋กœ

  • LOGIN page์ž„์„ ์•Œ๋ ค์ฃผ๋Š” <h1> tag

  • form์„ ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•œ <form> tag

  • ์‚ฌ์šฉ์ž๊ฐ€ ์–ด๋–ค ๊ฐ’์„ ์ž…๋ ฅํ•˜๋ฉด ๋˜๋Š” ์ง€ placeholder ์—ญํ• ์„ ํ•˜๋Š” <label> tag

  • ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•˜๋Š” ๊ฐ’์„ ๋ฐ›๋Š” <input> tag

  • ๋ฒ„ํŠผ ์—ญํ• ์˜ <button> tag

์ด์™€ ๊ฐ™์ด element๊ฐ€ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

<form> tag์˜ action ๊ฐ’์ด "result.php"์ธ ๊ฑธ ๋ณด์•„ ์‚ฌ์šฉ์ž๊ฐ€ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ „๋‹ฌํ•˜๋ฉด

๊ทธ ๋‹ค์Œ์œผ๋กœ ์‹คํ–‰๋˜๋Š” ์ฝ”๋“œ๊ฐ€ result.php์ž„์„ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

๊ทธ๋Ÿผ ์ด๋ฒˆ์—” result.php code๋ฅผ ํ™•์ธํ•ด๋ณด์ž!

[result.php]

<?php
$user = $_POST['name'];
$password = $_POST['password'];


if($user == 'admin' && $password == 'admin1234') {
    header("Location: ./result.html");
} else {
    echo 
    '<script>
        alert("WARNING!!! Who are you.");
        location.href = "./index.html";
    </script>';
}
?>

result.php๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ username & password๋ฅผ $_POST์—์„œ ๊ฐ€์ ธ์™€ ๊ฐ๊ฐ

๋ณ€์ˆ˜$user, $password์— ํ• ๋‹นํ•œ๋‹ค.

๋งŒ์•ฝ ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•œ ๊ณ„์ •์ด admin:admin1234๋ผ๋ฉด result.html๋กœ ์ด๋™ํ•˜๊ณ 

๊ทธ ๋ฐ–์˜ ๊ฒฝ์šฐ๋Š” ๋ชจ๋‘ POP up์ฐฝ์„ ๋„์šด ๋’ค, ๋‹ค์‹œ index.html๋กœ ์ด๋™ํ•œ๋‹ค.

์ฆ‰ ์šฐ๋ฆฌ๊ฐ€ ๋งŒ์กฑ ์‹œํ‚ค๊ณ ์ž ํ•˜๋Š” ์กฐ๊ฑด์— ๋ถ€ํ•ฉํ•  ๋•Œ๋งŒ result.html๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ!

๊ทธ๋ ‡๋‹ค๋ฉด result.html์ด ์–ด๋–ป๊ฒŒ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋Š” ์ง€ ํ™•์ธํ•ด๋ณด์ž.

[result.html]

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Result</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <h1>WELCOME!!</h1>
        <p>Hello, Aaaaaaadmin.<br> How are you today? =D</p>
        <button class="logout_btn" id="logout_btn">Logout</button>
    </div>
    <script src="./logout.js"></script>
</body>
</html>

result.html๋กœ ์ ‘๊ทผํ•˜๋ฉด <h1> & <p> tag์— ์ ํžŒ ๋ฌธ๊ตฌ์™€ Logout ๋ฒ„ํŠผ์„ ๋ณผ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค.

์ด๋•Œ ๋ฒ„ํŠผ์€ <form> tag ์•ˆ์— ์œ„์น˜ํ•˜์ง€ ์•Š์ง€๋งŒ

๋ฒ„ํŠผ์œผ๋กœ์จ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด ์งง์€ JS code๋ฅผ ์ž‘์„ฑํ–ˆ๋‹ค.

[logout.js]

const btn = document.getElementById("logout_btn");

btn.addEventListener('click', ()=> {
    window.location.replace("./index.html")
})

result.html์— ์žˆ๋Š” element ์ค‘ id๊ฐ€ "logout_btn"์ธ ๊ฑธ ์ฐพ์•„์„œ btn์ด๋ผ ์ด๋ฆ„์„ ๋ถ™์ธ๋‹ค.

๋งŒ์•ฝ btn์— "click"์ด๋ผ๋Š” ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๊ฒŒ ๋˜๋ฉด index.html๋กœ ์ด๋™ํ•˜๋ผ๋Š” ์ฝ”๋“œ์ด๋‹ค.

์‚ฌ์šฉ์ž๊ฐ€ Logout ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด ์ด ์ฝ”๋“œ๊ฐ€ ๋™์ž‘ํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— result.html์—์„œ

<script> tag๋กœ js code๋ฅผ ์—ฐ๊ฒฐํ•ด์ค€ ๊ฒƒ!

CSS๋ฅผ ์ œ์™ธํ•œ ๋ชจ๋“  ์ฝ”๋“œ๋ฅผ ํ™•์ธํ–ˆ์œผ๋‹ˆ ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜๋Š” ์ง€, ํ™”๋ฉด์œผ๋กœ ํ™•์ธํ•ด๋ณด์ž!


lndex.html๋กœ ์ ‘๊ทผํ•˜๋ฉด LOGIN form์ด ๋“ฑ์žฅํ•œ๋‹ค.

admin:admin1234๋ฅผ ์ž…๋ ฅํ•˜๊ณ  Log in ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๋ฉด

if๋ฌธ ์กฐ๊ฑด์„ ๋งŒ์กฑํ•˜๊ธฐ ๋•Œ๋ฌธ์— Logout ๋ฒ„ํŠผ์ด ์ œ๊ณต๋˜๋Š” result.html๋กœ ์ด๋™ํ•˜๊ฒŒ ๋˜๊ณ 

admin:admin1234๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ๊ณ„์ •์„ ์ž…๋ ฅํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š”

POP up ์ฐฝ์ด ๋„์›Œ์ง€๋Š” ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

logout ๋ฒ„ํŠผ์„ ๋ˆ„๋ฅด๊ฑฐ๋‚˜ pop up ์ฐฝ์„ ๋‚ด๋ฆฐ ํ›„์—๋Š” ๋‹ค์‹œ index.html๋กœ ๋Œ์•„๊ฐ„๋‹ค!

ํŽ˜์ด์ง€๋Š” ์ž˜ ๋™์ž‘ํ•˜๋Š” ๊ฑฐ ๊ฐ™์œผ๋‹ˆ ์ด์ œ ๋งˆ์ง€๋ง‰์œผ๋กœ CSS code๋ฅผ ํ™•์ธํ•ด๋ณด์ž!


[style.css]

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}
body {
    display: grid;
    place-items: center;
    height: 100vh;
}
.container {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    height: 400px;
    width: 340px;
    border-radius: 10px;
    padding: 20px;
    background-color: #eee;
}
h1 {
    text-align: center;
}
form {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 65%;
}
label {
    font-size: 20px;
    font-weight: bold;
}
input {
    width: 100%;
    padding: 5px;
    border: none;
    border-bottom: 1px solid rgb(1, 88, 88);
    outline: none;
    background-color: #eee;
    font-size: 18px;
}
p {
    text-align: center;
    font-size: 20px;
}
.login_btn {
    font-size: 20px;
    font-weight: bold;
    border: none;
    padding: 5px;
    cursor: pointer;
    background-color: rgb(1, 88, 88);
    margin-top: 10px;
    color: #fff;
}
.logout_btn {
    font-size: 20px;
    font-weight: bold;
    border: none;
    padding: 5px;
    cursor: pointer;
    background-color: rgb(128, 0, 0);
    margin-top: 10px;
    color: #fff;
}

html code๋ฅผ ๋ณด๋ฉด ๋ชจ๋‘ style.css๋ฅผ ์—ฐ๊ฒฐํ•œ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ

์ด๋Š” ์ „์ฒด์ ์œผ๋กœ ๋™์ผํ•œ ์Šคํƒ€์ผ์„ ์ž…ํžˆ๊ณ , ๋‹ค๋ฅด๊ฒŒ ์Šคํƒ€์ผ์„ ์ ์šฉํ•  ๋ถ€๋ถ„๋งŒ

์„ ํƒ์ž๋กœ ๊ตฌ๋ถ„ํ•ด ํ•˜๋‚˜์˜ ํŒŒ์ผ๋กœ ์ฝ”๋“œ๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•จ์ด๋‹ค.

๊ทธ๋ž˜์„œ CSS๋ฅผ ๋ณด๋ฉด login_btn & logout_btn์„ ์ œ์™ธํ•œ ๋‹ค๋ฅธ tag๋Š” ๋™์ผํ•˜๊ฒŒ ์Šคํƒ€์ผ์ด ์ ์šฉ๋˜๊ณ 

button๋งŒ ํด๋ž˜์Šค๋ฅผ ๊ฐ๊ฐ ์ง€์ •ํ•ด ์ƒ‰์ƒ์„ ๋‹ค๋ฅด๊ฒŒ ์ž…ํžˆ๊ณ  ์žˆ๋‹ค.

๋งŒ์•ฝ result.html์„ ์œ„ํ•ด CSS ํŒŒ์ผ์„ ๋”ฐ๋กœ ์ž‘์„ฑํ•˜๊ฒŒ ๋˜๋ฉด

style.css ๋‚ด์šฉ๊ณผ ๊ฑฐ์˜ ์ค‘๋ณต๋˜๋Š” ํŒŒ์ผ์ด ํ•˜๋‚˜ ๋” ์ƒ๊ธฐ๋Š” ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์—

์ด์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ ์ฝ”๋“œ์˜ ์–‘์„ ์ค„์ผ ์ˆ˜ ์žˆ๋‹ค!!

Last updated