์์ ๋ฒ์ ์ธ ์ธ์คํ๊ทธ๋จ ๋ก๊ทธ์ธ ํ์ด์ง๋ฅผ ์ฝ๊ฐ์ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ๋ฃ์ด์ ๋ก๊ทธ์ธ ํ ์ ์๊ฒ ๊ตฌํํด๋ดค์ต๋๋ค.
๋ถ์กฑํ์ง๋ง ์ฝ๋๋ค์ ๋ณด๋ฉด์ ๋ถ์์๋ ๋ถ์๊ณผ ์๊ฐ๋ค์ ์ ์ด๋ณด๊ฒ ์ต๋๋ค.
HTML
CSS
JavaScript
@
ํฌํจ ๋น๋ฐ๋ฒํธ 5์๋ฆฌ ์ด์ ์ผ๋ ๋ก๊ทธ์ธ๋ฒํผ ํ์ฑํ ๋ฐ ๋ฒํผ ์ ๋ณ๊ฒฝ<main class="main-box">
<div class ="container">
<span class="logo-text">Sunstagram</span>
<input type="text" id="id-email" placeholder="์ ํ๋ฒํธ, ์ฌ์ฉ์ ์ด๋ฆ ๋๋ ์ด๋ฉ์ผ" />
<input type="password" id="password" placeholder="๋น๋ฐ๋ฒํธ" />
<button type="button" onclick="location.href='main.html'" class="button button-off" id="login-button" disabled>๋ก๊ทธ์ธ</button>
<div class="validity">์์ด๋ ๋๋ ๋น๋ฐ๋ฒํธ๊ฐ ์๋ชป ์
๋ ฅ ๋์ด ์์ต๋๋ค.</div>
<a href="">๋น๋ฐ๋ฒํธ๋ฅผ ์์ผ์
จ๋์?</a>
</div>
</main>
HTML
์ฝ๋๋ง ์์ฑํ๋ฉด ์์ ์ฌ์ง์ฒ๋ผ ๋ง๋ค์ด ์ง๋๋ค.
์๋์ ์ด๋ค ์์๋ก ์ฝ๋๋ค์ ์ ์๋์ง ๋ด๋ณด๊ฒ ์ต๋๋ค.
CSS
๋ฅผ ํธํ๊ฒ ์ ์ฉํ ์ ์๋๋ก ๋ชจ๋ ํ๊ทธ๋ค์ div
๋ก ๋ฌถ์ด์คฌ์ต๋๋ค.div
์ Flex
๋ฅผ ์ค์ ์ธ๋ก๋ก ์ ๋ ฌ ํ๋ค ์๊ฐํ๊ณ ํ๊ทธ๋ค์ ์์๋๋ก ์
๋ ฅํฉ๋๋ค..main-box{
display: flex;
justify-content: center;
margin-top: 6%;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 350px;
height: 380px;
background-color: rgb(255, 255, 255);
border: 1px solid rgb(219, 219, 219);
}
.logo-text {
margin-top: -70px;
margin-bottom: 40px;
font-family: 'Lobster', cursive;
font-size: 42px;
font-weight:bolder;
}
input {
width: 270px;
height: 37px;
margin-bottom: 7px;
padding-left: 8px;
color: rgb(142, 142, 142);
outline-style: none;
border: 1px solid rgb(219, 219, 219);
border-radius: 4px;
background-color: rgb(250, 250, 250);
font-size: 12px;
}
.button {
width: 270px;
height: 30px;
margin: 7px 0px;
color: white;
background-color: #0095f6;
border: 0px solid;
border-radius: 5px;
}
.button-off {
background-color: #b9dffc;
cursor: not-allowed;
}
.container>div {
font-size: 13px;
font-weight: 400;
}
.validity {
display: none;
}
a {
position: relative;
bottom: -80px;
font-size: 12px;
text-decoration: none;
}
์ ์ฌ์ง์ HTML
๊ณผ CSS
๋ง ์ ์ฉ ์ํจ ํ๋ฉด์
๋๋ค
ํธํ๊ฒ ์ฌ์ฉ ๊ฐ๋ฅํ display
: flex
๋ฅผ ์ฌ์ฉํ ๋ ค๊ณ ๋
ธ๋ ฅ์ ๋ง์ด ํ์ต๋๋ค.
main-box
์ flex
justify-content: center
๋ฅผ ์ค์ ๊ฐ์ด๋ฐ๋ก ์ ๋ ฌ ์์ผฐ์ต๋๋ค.
๋ก๊ณ ํ
์คํธ ์์ด๋ ๋น๋ฐ๋ฒํธ์นธ ๋ฒํผ ๋ค์ ํ๊ณ ์๋ container
์ flex
๋ฅผ ์ฃผ๊ณ flex-direction: column
์ ์ฉ์์ผ ์ธ๋ก๋ก ์ ๋ ฌ ํ์ต๋๋ค.
const button = document.getElementById('login-button');
const idIn = document.getElementById('id-email');
const passwordIn = document.getElementById('password');
const validity = document.getElementsByClassName("validity")[0]
const container = document.getElementsByClassName("container")[0]
// id์ @ password 5์์ด์ ์ ํจ์ฑ ๊ฒ์ฌ ๋ฐ ๋ฒํผํ์ฑํ
function login() {
const id= idIn.value
const password = passwordIn.value
if (id.includes("@") && (password.length >= 5)) {
button.classList.remove("button-off")
button.disabled = false;
validity.style.display = 'none';
} else {
button.classList.add("button-off")
button.disabled = true;
validity.style.display = 'block';
}
}
// ์ํฐ ์น๋ฉด ๋ฒํผ ํด๋ฆญ
function enter(e) {
if(e.keyCode == 13) {
button.click();
}
}
container.addEventListener('keyup',login);
// idIn.addEventListener('keyup',login);
container.addEventListener('keypress',enter);
// idIn.addEventListener('keypress',enter);
class
์ id
๋ช
์ผ๋ก ๋ก๊ทธ์ธ๋ฒํผ, ์์ด๋, ๋น๋ฐ๋ฒํธ, ์ธํ์ฐฝ์ ์ง์ ํด๋๊ณ ๋ก๊ทธ์ธ์ด๋ผ๋ ํจ์ ์์@
์ ๋น๋ฐ๋ฒํธ ์นธ์ด 5์๋ฆฌ ์ด์์ ํ์ธํ๋ ์กฐ๊ฑด๋ฌธ์ ๋ฃ์ button-off
์ ์ญ์ ,disabled
์false
๊ฐ์ ์ค์ ๋ฒํผ ํ์ฑํdisplay : none
์ ์ ์ฉ ์์ ๋ก๊ทธ์ธํ์ด์ง๋ฅผ ํด๋ก ํด๋ณด๋ฉด์ ๊ทธ๋๋ ์ต์ํ์ง ์์๋ flex
๊ฐ๋
๋ ๋ค์ ์ก๊ณ ์ด๋ฒคํธ๋ฅผ ๋ฃ์ด๋ณด๋๊ฑธ ์ฒ์ํด๋ณด๋ฉด์ ์ด๋ค์์ผ๋ก ์ ์ฉ๋๋์ง ์์ ๊ฐ์์์ด์ ์ข์ ๊ฒฝํ์ด์๋ค๊ณ ์๊ฐ์ ํ๋ค. ๋ค์ ๋ฉ์ธํ๋ฉด์ ๋ํด ๊ธ์ ์ธ๋๋ ์ข๋ ์ ๋ฆฌ๋๊ณ ๋ด๊ฐ ์ด๋ค ์๊ฐ์ํ๋ฉด์ ์ด๋ฐ ์ฝ๋๋ฅผ ํ๋์ง ์ ์ด๋ด์ผ ๊ฒ ๋ค.