Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

74
Vistas
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:

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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.

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.