1
resposta

[Projeto] Como ocultar e mostrar diferentes elementos em css

Estou terminando de fazer uns acabamentos no meu projeto e não consigo fazer com que eu esconda a imagem quando sair o texto criptografado, ou a imagem fica la ou tenho q remove-la do codigo, alguem consegue dar uma luz? Segue os codigos:

<!DOCTYPE html>
<html lang="pt-br">
<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">
    <title>Decodificador</title>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link rel="stylesheet" href="assets/reset.css">
    <link rel="stylesheet" href="assets/style.css">
</head>
<body>
    <header>
            <div class="logoAlura">
                <img src="assets/img/Frame 6.png" alt="Logo da Alura" class="imgLogo">
            </div>
    </header>
    <main>
        <section>
            <textarea class="text-area" cols="41" rows="4" placeholder="Digite seu texto"></textarea>
                <div class="information">
                    <h6>Apenas letras minusculas e sem acento.</h6>
            </div>    
            <div class="buttons">
                <button class="btn-encrypt" onclick="btnEncrypt()">Criptografar</button>
                <button class="btn-decrypt" onclick="btnDecrypt()">Descriptografar</button>
            </div>
        </section>    
        <section>
            <textarea class="message" cols="20" rows="10"></textarea>
            <button class="btn-copy" onclick="copyText()">Copiar</button>
        </section>
    </main>
    <footer>
    </footer>
    <script src="assets/script.js"></script>
</body>
</html>

CSS

* {
    background: #E5E5E5;
    font-family: 'Inter', sans-serif;
    font-weight: 400;
    font-size: 32px;
    line-height: 150%;
}

.logoAlura {
    margin-left: 10px;
    padding-top: 10px;
    width: 2%;
}

main {
    display: flex;
    margin-bottom: 50px;
    margin-left: 80px;
}

.text-area {
    border: none;
    color: #0a3871;
    margin-top: 90px;
    text-transform: lowercase;
}

::placeholder { color: #0a3871;}
    .text-area:focus{
        outline: none;
    }

.message {
    background: white;
    background-image: url(/assets/img/1.PNG.png);
    background-repeat: no-repeat;
    border: none;
    box-shadow: 0px 24px 32px -8px rgba(0, 0, 0, 0.08);
    border-radius: 32px;
    color: #0a3871;
    margin-left: 98px;
    margin-top: 20px;
    padding-left: 20px;
    position: fixed;
}

.message:focus {
    outline: none;
}

.buttons {
    display: flex;
    margin-top: 18px;
}

.btn-encrypt {
    background: #d8dfe8;
    border: 1px solid #0a3871;
    border-radius: 24px;
    color: #0a3871;
    cursor: pointer;
    height: 67px;
    margin-left: 30px;
    width: 328px;
}
.btn-decrypt {
    background-color: #0a3871;
    border: 1px solid #0a3871;
    border-radius: 24px;
    color: white;
    cursor: pointer;
    height: 67px;
    width: 328px;
}

.btn-copy {
    border: 1px solid #0a3871;
    border-radius: 24px;
    color: #0a3871;
    cursor: pointer;
    height: 67px;
    margin-left: 108px;
    margin-top: 402px;
    position: absolute;
    width: 336px;
}

.information{
    color: #495057;
    font-size: 18px;
}
1 resposta

Olá Luan, tudo bem?

Para ocultar e mostrar diferentes elementos em CSS, você pode utilizar a propriedade "display". Por exemplo, se você quiser esconder a imagem quando o texto estiver criptografado, você pode adicionar a seguinte linha de código no seu CSS:

.imgLogo {
  display: none;
}

Assim, quando o texto for criptografado, a imagem será ocultada. E para mostrar novamente a imagem, basta remover essa linha de código.

Espero ter ajudado e bons estudos!