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

99
Views
Mostrar algo de HTML para cuando no se puede mostrar un <img> (en lugar de la imagen)

Resulta que tengo una imagen estilizada con una lista dentro en alguna página HTML.

Si no se puede mostrar la imagen, quiero tener una lista HTML normal en su lugar (de forma similar a un texto alternativo, pero con etiquetas HTML y no solo texto).

¿Hay una mejor manera de hacer eso? (como una regla CSS o algo así?)

Gracias

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Hay una forma estándar de hacer esto sin recurrir a JavaScript. Utilice el elemento objeto en lugar del elemento img. Si la imagen no se puede mostrar, se utiliza el contenido del elemento del objeto. Asi que:

 <p>When the image displays:</p> <object data="https://via.placeholder.com/50" style="height:50px"> <ul> <li>list item 1</li> <li>list item 2</li> </ul> </object> <p>When the image doesn't display:</p> <object data="https://error.placeholder.com/50" style="height:50px"> <ul> <li>list item 1</li> <li>list item 2</li> </ul> </object>

about 4 years ago · Juan Pablo Isaza Report

0

la lista se superpone normalmente a la imagen. si la imagen tiene un error al cargar, se volverá invisible.

aunque no estoy 100% seguro de que funcione.

CSS:

 img { z-index: 1; position: absolute; top:0px; left:0px; } ul { /*z-index: 0;*/ position: absolute; top:0px; left:0px; }

html:

 <ul> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul> <img src="image.jpg" onerror="document.querySelector('img').style.visibility = "hidden"">

puede diseñar la lista como desee.

about 4 years ago · Juan Pablo Isaza Report

0

Puede escuchar el evento de error , que se activa cuando el recurso no se puede cargar:

 function badImage(imageElement){ imageElement.outerHTML = "This image can't be shown" }
 <img src="https://.com" onerror="badImage(this)">

about 4 years ago · Juan Pablo Isaza Report
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!