【问题标题】:Why my overlay container is not moving left when I click SIGN UP button?当我单击 SIGN UP 按钮时,为什么我的覆盖容器没有向左移动?
【发布时间】:2022-01-21 03:54:37
【问题描述】:

这是我的代码盘链接:https://codepen.io/xaviour1504/pen/zYEzGLJ 当我尝试单击注册按钮时,只有登录部分向右移动,但覆盖容器部分没有向左移动。这是我的代码

    /* move overlay to left */
    .container.right-panel-active.overlay-container {
        transform: translateX(-100%);
    }

【问题讨论】:

    标签: javascript html css transform


    【解决方案1】:

    您没有正确选择叠加层。

    用途:

    .container.right-panel-active .overlay-container
    

    也就是说,当设置了 right-panel-active 类时,将选择一个具有 overlay-container 类的子项(这就是空间的用途)。

    【讨论】:

      【解决方案2】:

      尝试使用这些值:

      /* move sign in to the right */
      .container.right-panel-active .sign-in-container {
          transform: translateX(-100%);
      }
      /* move overlay to left */
      .container.right-panel-active.overlay-container {
          transform: translateX(100%);
      }
      

      请看这里:

      const signUpButton = document.getElementById('signUp');
      const signInButton = document.getElementById('signIn');
      const content = document.getElementById('container');
      
      signUpButton.addEventListener('click', () =>
          content.classList.add('right-panel-active')
      );
      
      signInButton.addEventListener('click', () =>
          content.classList.remove('right-panel-active')
      );
      @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@600&display=swap');
      
      * {
          box-sizing: border-box;
      }
      
      body {
          font-family: 'Montserrat', sans-serif;
          background-color: rgb(238, 229, 229);
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          height: 100vh;
          margin: -20px 0 50px;
          overflow: hidden;
      }
      
      h1 {
          font-weight: bolder;
          margin: 0;
      }
      
      p {
          font-size: 15px;
          font-weight: 100;
          letter-spacing: 0.5px;
          line-height: 20px;
          margin: 20px 0 30px;
      }
      
      span {
          font-size: 15px;
          line-height: 20px;
          letter-spacing: 0.5px;
          font-weight: 100;
      }
      
      a {
          color: #333;
          text-decoration: none;
          font-size: 15px;
          margin: 15px 0;
      }
      
      .container {
          background-color: white;
          border-radius: 10px;
          box-shadow: 0 15px 30px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22);
          position: relative;
          overflow: hidden;
          width: 800px;
          max-width: 100%;
          min-height: 490px;
      }
      
      .form-container form {
          background: white;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          height: 100%;
          padding: 0 50px;
          text-align: center;
      }
      
      .social-container {
          margin: 20px 0;
      }
      
      .social-container a {
          border: solid 2px #ddd;
          border-radius: 50%;
          display: inline-flex;
          justify-content: center;
          align-items: center;
          margin: 0 5px;
          width: 40px;
          height: 40px;
      }
      
      .form-container input {
          background: #eee;
          border: none;
          padding: 12px 15px;
          margin: 8px 0;
          width: 100%;
      }
      
      button {
          border: 1px solid orangered;
          border-radius: 20px;
          background: orangered;
          color: white;
          font-size: 15px;
          font-weight: 100;
          padding: 10px 40px;
          letter-spacing: 1px;
          transition: transform 80ms ease-in;
      }
      
      button:active {
          transform: scale(0.95);
      }
      
      button:focus {
          outline: none;
      }
      
      button.ghost {
          background: transparent;
          border-color: white;
      }
      
      .form-container {
          position: absolute;
          top: 0;
          height: 100%;
          transition: all 0.6s ease-in-out;
      }
      
      .sign-in-container {
          left: 0;
          width: 50%;
          z-index: 1;
      }
      .sign-up-container {
          opacity: 0;
          width: 50%;
          z-index: 1;
      }
      .overlay-container {
          position: absolute;
          top: 0;
          left: 50%;
          width: 50%;
          height: 100%;
          overflow: hidden;
          transition: transform 0.6s ease-in-out;
          z-index: 100;
      }
      .overlay {
          background: #ff416c;
          background: linear-gradient(to right, #ff4b2b, #ff416c) no-repeat 0 0 / cover;
          color: white;
          position: relative;
          left: -100%;
          height: 100%;
          width: 200%;
          transform: translateX(0);
          transition: transform 0.6s ease-in-out;
      }
      
      .overlay-panel {
          position: absolute;
          top: 0;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          padding: 0 40px;
          height: 100%;
          width: 50%;
          text-align: center;
          transform: translateX(0);
          transition: transform 0.6s ease-in-out;
      }
      
      .overlay-right {
          right: 0;
          transform: translateX(0);
      }
      
      .overlay-left {
          transform: translateX(-20%);
      }
      
      /* animation */
      
      /* move sign in to the right */
      .container.right-panel-active .sign-in-container {
          transform: translateX(-100%);
      }
      /* move overlay to left */
      .container.right-panel-active.overlay-container {
          transform: translateX(100%);
      }
      <div class="container" id="container">
                  <div class="form-container sign-up-container">
                      <form action="#">
                          <h1>Create Account</h1>
                          <div class="social-container">
                              <a href="#" class="social"><i class="fab fa-facebook"></i></a>
                              <a href="#" class="social"><i class="fab fa-google-plus-g"></i></a>
                              <a href="#" class="social"><i class="fab fa-linkedin"></i></a>
                          </div>
                          <span>or use your email for registration </span>
                          <input type="text" placeholder="Name" />
                          <input type="email" placeholder="Email" />
                          <input type="Password" placeholder="Password" />
                          <button>SIGN UP</button>
                      </form>
                  </div>
                  <div class="form-container sign-in-container">
                      <form action="#">
                          <h1>Sign in</h1>
                          <div class="social-container">
                              <a href="#" class="social"><i class="fab fa-facebook"></i></a>
                              <a href="#" class="social"><i class="fab fa-google-plus-g"></i></a>
                              <a href="#" class="social"><i class="fab fa-linkedin"></i></a>
                          </div>
                          <span>or use your account </span>
                          <input type="email" placeholder="Email" />
                          <input type="Password" placeholder="Password" />
                          <a href="#">Forgot your password?</a>
                          <button>SIGN IN</button>
                      </form>
                  </div>
                  <div class="overlay-container">
                      <div class="overlay">
                          <div class="overlay-panel overlay-left">
                              <h1>Welcome Back!</h1>
                              <p>
                                  To keep connected with us please login with your personal info
                              </p>
                              <button class="ghost" id="signIn">SIGN IN</button>
                          </div>
                          <div class="overlay-panel overlay-right">
                              <h1>Hello, Friend!</h1>
                              <p>Enter your personal details and start journey with us</p>
                              <button class="ghost" id="signUp">SIGN UP</button>
                          </div>
                      </div>
                  </div>
              </div>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-22
        • 2020-07-23
        • 2020-10-11
        • 1970-01-01
        • 2011-05-05
        • 1970-01-01
        • 2021-04-20
        • 1970-01-01
        相关资源
        最近更新 更多