Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

170
Visualizações
html form styling moving line idk how to fix that is anyone can give me advice?

I'm adding a message to the right side of the input box using span/span and when I run these codes it's working well but when I enter the passwords the Confirm password line is moving to the left side. Is there is any way to fix that?

Thank you for your interest.

Before: before

After: after

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="jquery.min.js"></script>
    <title>Document</title>
    <style>
        body{background-color: black; color: darkgreen;}
        form{text-align: center;}
        
        ::placeholder{
            color: red;
            opacity: 0.5;
        }
    </style>
</head>
<body>
    <form>
        <p id="firstname">First name</p>
        <input type="text" id="firstnameInput">

        <p id="lastname">Last name</p>
        <input type="text" id="lastnameInput">

        <p id="email">E-mail</p>
        <input type="text" id="emailInput">

        <p>Password</p>
        <input type="password" id="password" onkeyup="check()" required>

        <p>Confirm password</p>
        <input type="password" id="confirm_password" onkeyup="check()" required>
        <span id='message'></span>

        <br><br>
        <input type="button" id="send" value="Send">
    </form>

    <script>

        var check = function() {
            if (document.getElementById('password').value ==
                document.getElementById('confirm_password').value) {
                document.getElementById('message').style.color = 'green';
                document.getElementById('message').innerHTML = 'Matching';
            } else {
                document.getElementById('message').style.color = 'red';
                document.getElementById('message').innerHTML = 'Not matching';
            }
        };
     
    </script>
    
</body>
</html>
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

In general, it is better to adjust DOM element classes, and supply styling to match those classes, rather than manipulating styles directly.

Also, once you do a querySelector, if you are doing more than one thing with the element, you should save the result, rather than re-query.

TBH, I'm not sure which of these things made it work, but I'm not seeing the extreme left behavior any more.

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="jquery.min.js"></script>
    <title>Document</title>
    <style>
        body{background-color: black; color: darkgreen;}
        form{text-align: center;}
        
        .valid { 
            color: green;
        }
        .invalid { 
            color: red;
        }
        ::placeholder{
            color: red;
            opacity: 0.5;
        }
    </style>
</head>
<body>
    <form>
        <p id="firstname">First name</p>
        <input type="text" id="firstnameInput">

        <p id="lastname">Last name</p>
        <input type="text" id="lastnameInput">

        <p id="email">E-mail</p>
        <input type="text" id="emailInput">

        <p>Password</p>
        <input type="password" id="password" onkeyup="check()" required>

        <p>Confirm password</p>
        <input type="password" id="confirm_password" onkeyup="check()" required>
        <span id='message'></span>

        <br><br>
        <input type="button" id="send" value="Send">
    </form>

    <script>

        var check = function() {
            let message = document.getElementById('message');
            if (document.getElementById('password').value ==
                document.getElementById('confirm_password').value) {
                message.classList.add('valid');
                message.classList.remove('invalid');
                message.innerHTML = 'Matching';
            } else {
                message.classList.add('invalid');
                message.classList.remove('valid');
                message.innerHTML = 'Not matching';
            }
        };
     
    </script>
    
</body>
</html>
about 4 years ago · Juan Pablo Isaza Relatório

0

Your problem lies here <span id='message'></span>.

<span> is an inline element. means that it will always try to fit in the same line.

Use a block level element like <div> or <p> instead of span and your problem will be solved!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda