만드는 방법: 로그인 양식

CSS를 사용하여 반응형 로그인 양식을 만들어 보세요.

버튼을 클릭하면 로그인 양식이 열립니다:

직접 시도해 보세요

로그인 양식을 만드는 방법

단계1 - HTML 추가:

컨테이너에 이미지를 추가하고 각 필드에 입력 컨트롤(일치하는 레이블과 함께)을 추가합니다. <form> 요소로 그들을 감싸서 입력을 처리합니다.

우리의 PHP 교육 중에서 입력 정보 처리 방법에 대해 더 알아보세요.

<form action="action_page.php" method="post">
  <div class="imgcontainer">
    <img src="img_avatar2.png" alt="Avatar" class="avatar">
  </div>
  <div class="container">
    <label for="uname"><b>사용자 이름</b></label>
    <input type="text" placeholder="사용자 이름 입력" name="uname" required>
    <label for="psw"><b>비밀번호</b></label>
    <input type="password" placeholder="비밀번호 입력" name="psw" required>
    <button type="submit">로그인</button>
    <label>
      <input type="checkbox" checked="checked" name="remember"> 기억하기
    </label>
  </div>
  <div class="container" style="background-color:#f1f1f1">
    <button type="button" class="cancelbtn">취소</button>
    <span class="psw">비밀번호를 잊으셨나요? <a href="#">비밀번호?</a></span>
  </div>
</form>

第二步 - CSS 추가:

/* 경계선이 있는 양식 */
form {
  border: 3px solid #f1f1f1;
}
/* 전체 너비 입력 필드 */
input[type=text], input[type=password] {
  width: 100%;
  padding: 12px 20px;
  margin: 8px 0;
  display: inline-block;
  border: 1px solid #ccc;
  box-sizing: border-box;
}
/* 모든 버튼에 스타일을 설정합니다 */
button {
  background-color: #04AA6D;
  color: white;
  padding: 14px 20px;
  margin: 8px 0;
  border: none;
  cursor: pointer;
  width: 100%;
}
/* 버튼에 마우스 오버 효과 추가 */
button:hover {
  opacity: 0.8;
}
/* 취소 버튼의 추가 스타일 설정(빨간색) */
.cancelbtn {
  width: auto;
  padding: 10px 18px;
  background-color: #f44336;
}
/* 이 컨테이너 내의 프로필 이미지를 중앙에 배치 */
.imgcontainer {
  text-align: center;
  margin: 24px 0 12px 0;
}
/* 프로필 이미지 */
img.avatar {
  width: 40%;
  border-radius: 50%;
}
/* 컨테이너에 내부 여백 추가 */
.container {
  padding: 16px;
}
/* "비밀번호를 잊으셨나요" 텍스트 */
span.psw {
  float: right;
  padding-top: 16px;
}
/* 매우 작은 스크린에서 span과 취소 버튼의 스타일 변경 */
@media screen and (max-width: 300px) {
  span.psw {
    display: block;
    float: none;
  }
  .cancelbtn {
    width: 100%;
  }
}

직접 시도해 보세요

모달 로그인 양식을 만드는 방법

단계1 - HTML 추가:

<!-- 모달 로그인 양식 열기 버튼 -->
<button onclick="document.getElementById('id01').style.display='block'">Login</button>
<!-- 모달 -->
<div id="id01" class="modal">
  <span onclick="document.getElementById('id01').style.display='none'"
class="close" title="모달 닫기">×</span>
  <!-- 모달 내용 -->
  <form class="modal-content animate" action="/action_page.php">
    <div class="imgcontainer">
      <img src="img_avatar2.png" alt="Avatar" class="avatar">
    </div>
    <div class="container">
      <label for="uname"><b>사용자 이름</b></label>
      <input type="text" placeholder="사용자 이름 입력" name="uname" required>
      <label for="psw"><b>비밀번호</b></label>
      <input type="password" placeholder="비밀번호 입력" name="psw" required>
      <button type="submit">로그인</button>
      <label>
        <input type="checkbox" checked="checked" name="remember"> 기억하기
      </label>
    </div>
    <div class="container" style="background-color:#f1f1f1">
      <button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn">취소</button>
      <span class="psw">비밀번호를 잊으셨나요? <a href="#">비밀번호?</a></span>
    </div>
  </form>
</div>

第二步 - CSS 추가:

/* 모달(배경) */
.modal {
  display: none; /* 기본적으로 숨김 */
  position: fixed; /* 원지에 남아있음 */
  z-index: 1; /* 최상단에 배치 */
  left: 0;
  top: 0;
  width: 100%; /* 전체 너비 */
  height: 100%; /* 전체 높이 */
  overflow: auto; /* 필요시 스크롤 활성화 */
  background-color: rgb(0,0,0); /* 대체 색상 */
  background-color: rgba(0,0,0,0.4); /* 투명도 있는 검은색 */
  padding-top: 60px;
}
/* 모달 내용/창 */
.modal-content {
  background-color: #fefefe;
  margin: 5px auto; /* 상단 15% 거리로 고정 및 중앙 정렬 */
  border: 1px solid #888;
  width: 80%; /* 화면 크기에 따라 조금씩 다를 수 있습니다 */
}
/* 닫기 버튼 */
.close {
  /* 모달 밖의 우측 상단에 위치시킵니다 */
  position: absolute;
  right: 25px;
  top: 0;
  color: #000;
  font-size: 35px;
  font-weight: bold;
}
/* 호버링 상태의 닫기 버튼 */
.close:hover,
.close:focus {
  color: red;
  cursor: pointer;
}
/* 확대 애니메이션 추가 */
.animate {
  -webkit-animation: animatezoom 0.6s;
  animation: animatezoom 0.6s
}
@-webkit-keyframes animatezoom {
  from {-webkit-transform: scale(0)}
  to {-webkit-transform: scale(1)}
}
@keyframes animatezoom {
  from {transform: scale(0)}
  to {transform: scale(1)}
}

안내:모달 내용 외의 区域을 클릭하여 모달을 닫을 수 있습니다. (또는 단지 "x" 또는 "취소" 버튼을 사용하는 것만이 아닙니다):

<script>
// 모달을 가져옵니다
var modal = document.getElementById('id01');
// 사용자가 모달 밖의任何位置을 클릭할 때, 그를 닫습니다 
window.onclick = function(event) {
  if (event.target == modal) {
    modal.style.display = "none";
  }
}
</script>

직접 시도해 보세요

관련 페이지

교육:HTML 양식

교육:CSS 양식