-2

How to make the captcha at the center when I click the submit button? I am having a hard time centering the captcha in the center. Kindly take a look in the jsfiddle attached hehe

https://jsfiddle.net/rzant4kb/

<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" />

<button id="myBtn" class="btn-submit" type="submit">SUBMIT</button>




<br>
<!-- Trigger/Open The Modal -->
<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">

    <div class="modal-body">
      <p>Captcha Verification</p>


      <!--Captcha Verification-->

      <div class="wrapper">

        <div class="captcha-area">
          <div class="captcha-img">

            <span class="captcha"></span>
          </div>
          <button class="reload-btn"><i class="fas fa-redo-alt"></i></button>
        </div>

        <form action="#" class="input-area">
          <input type="text" placeholder="Enter captcha" maxlength="6" spellcheck="false" required>
          <button class="check-btn">Check</button>
        </form>
        <div class="status-text"></div>
      </div>

    </div>

  </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
Alex
  • 11
  • 4

1 Answers1

1

Centered the captcha input field using :

.wrapper{
    width: 65%;
    margin: 0 auto;
}

// Get the modal
        var modal = document.getElementById("myModal");
        
        // Get the button that opens the modal
        var btn = document.getElementById("myBtn");
        
        // Get the <span> element that closes the modal
        var span = document.getElementsByClassName("close")[0];
        
        // When the user clicks the button, open the modal 
        btn.onclick = function() {
          modal.style.display = "block";
        }
        
        // When the user clicks on <span> (x), close the modal
        span.onclick = function() {
          modal.style.display = "none";
        }
        
        // When the user clicks anywhere outside of the modal, close it
        window.onclick = function(event) {
          if (event.target == modal) {
            modal.style.display = "none";
          }
        }
        
        
        
* {
    margin: 0;
    border: 0;

}


hr { 
    border-color: #6ACEBC;
    border-style: solid; 
    border-width: 0.7vw;
    background:  #6ACEBC;
    height: 30px;
   
    }

.logo {
    width: 18%;
    display: block;
    margin-left: auto;
    margin-right: auto;
    margin-top: 75px;
}

.login {
    text-align: center;
    display: block;
    margin-top: 15px;
}


.username, .password {
    font-family: Arial, Helvetica, sans-serif;
    font-style: normal;
    font-weight: 700;
    font-size: 1vw;
    margin-right: 10px;
}
.input-details {
    border: black 1px solid;
    width: 16vw;
    height: 2vh;
}

.forgot-password {
    margin-left: 230px;
    text-decoration: none;
    color: #6ACEBC;
    font-family: Arial, Helvetica, sans-serif;
    margin-top: 20%;
    font-size: 75%;
}

.btn-submit {
    background: #C78632;
    border-radius: 301px;
    padding: 5px;
    color: white;
    font-weight: bold;
    margin-top: 20px;
    width: 150px;
    height: 30px;
}

.line {
   bottom: 0;
   position: absolute;
   background-color: #6ACEBC;
   width: 98.7%;
}

/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
  }
  
  /* Modal Content */
  .modal-content {
    position: relative;
    background-color: #fefefe;
    margin: auto;
    padding: 0;
    border: 1px solid #888;
    width: 50%;
    height: 50%;
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
    -webkit-animation-name: animatetop;
    -webkit-animation-duration: 0.4s;
    animation-name: animatetop;
    animation-duration: 0.4s;
    border-radius: 34px;
   
    
    
  }
  
  /* Add Animation */
  @-webkit-keyframes animatetop {
    from {top:-300px; opacity:0} 
    to {top:0; opacity:1}
  }
  
  @keyframes animatetop {
    from {top:-300px; opacity:0}
    to {top:0; opacity:1}
  }
  
  /* The Close Button */
  .close {
    color: white;
    float: right;
    font-size: 28px;
    font-weight: bold;
  }
  
  .close:hover,
  .close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
  }
  
 
  
  .modal-body {
    padding: 2px 16px;
    align-items: center;
  }

  .modal-body p {
    margin-top: 50px;
    font-weight: bold;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 25px;
    text-align: center;
  }

  .wrapper{
    width: 65%;
    margin: 0 auto;
  }

  .wrapper .captcha-area{
    display: flex;
    height: 65px;
    margin: 30px 50px 20px 0;
    align-items: center;
    justify-content: space-between;
    
  }
  .captcha-area .captcha-img{
    height: 100%;
    width: 345px;
    user-select: none;
    background: #9FFBA8;
    border-radius: 5px;
    position: relative;
  }
  .captcha-img img{
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 5px;
    opacity: 0.95;
  }
  .captcha-img .captcha{
    position: absolute;
    left: 50%;
    top: 50%;
    width: 100%;
    color: #000;
    font-size: 35px;
    text-align: center;
    letter-spacing: 10px;
    transform: translate(-50%, -50%);
    text-shadow: 0px 0px 2px #b1b1b1;
    font-family: 'Noto Serif', serif;
  }
  .wrapper button{
    outline: none;
    border: none;
    color: #000;
    cursor: pointer;
    background: #9FFBA8;
    border-radius: 5px;
    transition: all 0.3s ease;
  }
  .wrapper button:hover{
    background: #6ACEBC;
  }
  .captcha-area .reload-btn{
    width: 75px;
    height: 100%;
    font-size: 25px;
  }
  .captcha-area .reload-btn i{
    transition: transform 0.3s ease;
  }
  .captcha-area .reload-btn:hover i{
    transform: rotate(15deg);
  }
  .wrapper .input-area{
    height: 60px;
    width: 85%;
    position: relative;
    
  }
  .input-area input{
    width: 100%;
    height: 100%;
    outline: none;
    padding-left: 20px;
    font-size: 20px;
    border-radius: 5px;
    border: 1px solid #bfbfbf;
  }
  .input-area input:is(:focus, :valid){
    padding-left: 19px;
    border: 2px solid #4db2ec;
  }
  .input-area input::placeholder{
    color: #bfbfbf;
  }
  .input-area .check-btn{
    position: absolute;
    right: 7px;
    top: 50%;
    font-size: 17px;
    height: 45px;
    padding: 0 20px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%);
  }
  .input-area input:valid + .check-btn{
    opacity: 1;
    pointer-events: auto;
  }
  .wrapper .status-text{
    display: none;
    font-size: 18px;
    text-align: center;
    margin: 20px 0 -5px;
  }
  @media (max-width: 506px){
    body{
      padding: 0 10px;
    }
    .wrapper{
      padding: 22px 25px 35px;
    }
    .wrapper header{
      font-size: 25px;
    }
    .wrapper .captcha-area{
      height: 60px;
    }
    .captcha-area .captcha{
      font-size: 28px;
      letter-spacing: 5px;
    }
    .captcha-area .reload-btn{
      width: 60px;
      margin-left: 5px;
      font-size: 20px;
    }
    .wrapper .input-area{
      height: 55px;
    }
    .input-area .check-btn{
      height: 40px;
    }
    .wrapper .status-text{
      font-size: 15px;
    }
    .captcha-area .captcha-img{
      width: 250px;
    }
  }
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.9.2/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js" integrity="sha384-Atwg2Pkwv9vp0ygtn1JAojH0nYbwNJLPhwyoVbhoPwBhjQPR5VtM2+xf0Uwh9KtT" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" />

<button id="myBtn" class="btn-submit" type="submit">SUBMIT</button>




<br>
<!-- Trigger/Open The Modal -->
<!-- The Modal -->
<div id="myModal" class="modal">

  <!-- Modal content -->
  <div class="modal-content">

    <div class="modal-body">
      <p>Captcha Verification</p>


      <!--Captcha Verification-->

      <div class="wrapper">

        <div class="captcha-area">
          <div class="captcha-img">

            <span class="captcha"></span>
          </div>
          <button class="reload-btn"><i class="fas fa-redo-alt"></i></button>
        </div>

        <form action="#" class="input-area">
          <input type="text" placeholder="Enter captcha" maxlength="6" spellcheck="false" required>
          <button class="check-btn">Check</button>
        </form>
        <div class="status-text"></div>
      </div>

    </div>

  </div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
Webdeveloper_Jelle
  • 2,868
  • 4
  • 29
  • 55