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

252
Visualizações
How to style elements in an EJS file with a style.css file

I was just experimenting here and there with EJS, because I am new to it.

Then I thought, why not style elements with a conditional flow? Basically a particular element will look purple when the condition is true and it will look red when it is not. When I style the elements in the tag itself, it works, but it doesn't work when I link a style.css file with it.

<body>
    <%if(4>3){%>
    <h1 style="color: blue;">4 is more than 3</h1>
    <% }else{%>
    <h1 style="color: red;">Something is very wrong</h1>
    <% }%>
</body>

This worked properly.

But when I tried to style it in style.css, it didn't work. What is the reason?

EJS file:

<!DOCTYPE html>
<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">
    <link rel="stylesheet" href="./style.css">
    <title>To Do List</title>
</head>

<body>
    <%if(4>3){%>
        <h1 id="one">4 is more than 3</h1>
    <% }else{%>
        <h1 id="two">Something is very wrong</h1>
    <% }%>
</body>
</html>

CSS file:

#one{
    color: purple;
}
#two{
    color: red;
}

The output:

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

0

Are you sure you have exposed the files properly? Such as in Express.js you need to serve the static folder where your file is kept on root domain for this to work.

To check this, try going to your website and opening /style.css and see if it opens.

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