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

119
Visualizações
The correct styling is applied despite the targeting are different in JSX and CSS files

Currently I have the following code: FormInput.jsx:

import './FormInput.scss';

const FormInput = ({ label, ...otherProps} ) => {
    const { value } = otherProps;
    return (
        <div className="group">
            <input className="formInput" {...otherProps} />
            {label && (
                <label 
                    className={`${value.length ? 'shrink' : ''} formInput-label`}
                >{label}</label>
            )}
        </div>
    )
};

export default FormInput;

In FormInput.scss:

.formInput-label {
    transition: 300ms ease all;
    position: absolute;
    font-size: 18px;
    left: 5px;
    top: 10px;

    &.shrink {
        top: -14px;
    }
}

What I'm confused about is that the targeted class of the label in FormInput.jsx should compile to:

.shrink .formInput-label

But the one in the SASS file will compile to:

.formInput-label.shrink

My question is how does the correct styling still get applied if the class targeting in the JSX and SASS files aren't the same? The JSX has the classes in reverse order and a space in between.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The class attribute (or className in JSX) defines a list of classes. The syntax for classes is different in HTML and in CSS, but the order of classes on the same element does not matter in either.

JSX renders to HTML, so it renders as class="shrink formInput-label", which defines the list of classes ["shrink", "formInput-label"] and is compatible with the CSS selector .shrink.formInput-label.

Also, a CSS selector such as .shrink would match the element as well (just with a lower specifity rating), because it matches one of the classes in the list.

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