아래 두단계 소스

아래 두단계 소스

QA

신고된 글아래 두단계 소스

본문

신고가 접수되어 자동으로 블라인드 된 글입니다.
원글을 보시려면 를 클릭하세요.

The Options for Password Revealing Inputs | CSS-Tricks

 

https://css-tricks.com/the-options-for-password-revealing-inputs/

 



const button = document.querySelector("button");
const oldMethodInput = document.querySelector(".old-method input");

button.addEventListener("click", () => {
  document.documentElement.classList.toggle("show-passwords");
  if (oldMethodInput.getAttribute("type") === "password") {
    oldMethodInput.setAttribute("type", "text");
  } else {
    oldMethodInput.setAttribute("type", "password");
  }
});

 
--
html 내용

<main>
  <div>
    <button>toggle security</button>
  </div>

  <form class="old-method">
    <h2>Classic Technique</h2>
    <input type="password" value="password">
    <p>Flop out <code>type="password"</code> for <code>type="text"</code> in HTML.</p>
    <p>⚠️ Downsides: doesn't play nice with all password managers.</p>
  </form>

  <form class="alt-1">
    <h2>WebKit-Specific Technique</h2>
    <input type="text" value="password">
    <p>Use <code>type="text"</code> with <code>-webkit-text-security</code> in CSS.</p>
    <p>⚠️ Downsides: Not using the sematically correct input type. Doesn't work in all browsers and probably never will.</p>
  </form>

  <form class="alt-2">
    <h2>Modern CSS Technique</h2>
    <input type="password" value="password">
    <p>Use <code>input-security</code> in CSS.</p>
    <p>⚠️ Downsides: Not supported in all browsers yet.</p>
  </form>
</main>

--- 
css 내용
 

.alt-1 input {
  -webkit-text-security: square;
}
.show-passwords .alt-1 input {
  -webkit-text-security: none;
  /* https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-text-security */
}

.show-passwords .alt-2 input {
  input-security: none;
  /* https://drafts.csswg.org/css-ui/#input-security */
}

form {
  display: grid;
  grid-template-columns: 1fr minmax(300px, min-content) 1fr;
  background: #546e7a;
  box-shadow: inset 0 0 100px rgb(0 0 0 / 0.4);
  border-bottom: 1px solid rgba(255 255 255 / 0.4);
  border-top: 1px solid rgba(0 0 0 / 0.4);
  color: white;
  padding: 2rem;
}
form > * {
  grid-column: 2 / 3;
}
html {
  font: 100%/1.4 system-ui;
}
h2 {
  margin: 0 0 0.5rem 0;
}
p {
  margin: 0.5rem 0;
}
body {
  margin: 0;
}
main div {
  background: #f4511e;
  text-align: center;
  padding: 2rem;
  position: sticky;
  top: 0;
}
button {
  border: 0;
  font: 130%/1.4 system-ui;
  background: white;
  border-radius: 6px;
  padding: 0.5rem 2rem;
}
button:hover,
button:focus {
  background: #eee;
}
button:active {
  position: relative;
  top: 1px;
}
input {
  font: 150%/1.4 system-ui;
}

 

toggle 버튼 대신 select 의 option 항목 선택으로  동일효과 나타내도록

이 질문에 댓글 쓰기 :

답변 1

답변을 작성하시기 전에 로그인 해주세요.
전체 150
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT