Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
¿Cómo separar el estilo, HTML y JS para este componente HTML reutilizable?

En mi proyecto, no puedo usar un marco JS moderno como React, solo puedo usar HTML + JS + CSS. Pero todavía quiero crear componentes reutilizables. Leí este enlace , que introdujo los componentes reutilizables HTML. Codifique de la siguiente manera:

Navbar.js

 class Navbar extends HTMLElement { constructor() { super(); } connectedCallback() { this.innerHTML = ` <style> nav { height: 40px; display: flex; align-items: center; justify-content: center; background-color: #000000; } ...... </style> <header> <nav> <ul> <li><a href="about.html">About</a></li> <li><a href="work.html">Work</a></li> <li><a href="contact.html">Contact</a></li> </ul> </nav> </header> `; } } customElements.define('navbar-component', Navbar);

Esto funciona bien ya que solo necesito escribir <navbar-component></navbar-component> cuando quiero reutilizarlo. Sin embargo, ¿hay alguna forma de separar HTML y CSS de Navbar.js? Entonces, ¿podría tener Navbar.css que contiene todo CSS y Navbar.html que contiene todo HTML? ¿Todo lo que necesito hacer es importar Navbar.css y Navbar.html en Navbar.js ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!