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

210
Views
Cada vez que cambio la imagen, img cambia de tamaño

Quiero hacer que la etiqueta img sea estricta. En mi ejemplo, cada vez que cambio la imagen, el tamaño también cambia.

Aquí hay un ejemplo: ingrese la descripción de la imagen aquí

 .cat { width:200px } img { max-width: 100%; height: auto; }
 <!DOCTYPE html> <html> <head> <title>HTML, CSS and JavaScript demo</title> </head> <body> <div class="cat"> <img src="https://loremflickr.com/400/400" /> </div> </body> </html>

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

0

Está haciendo max-width:100% y height:auto , que lo deja ir a su tamaño predeterminado si desea que tengan el mismo tamaño, el mismo ancho que el gato y el mismo ancho que el img:

 .cat { width:200px; height:200px; } img { width:200px; height: 200px; }

Y en ese momento no necesitas el .cat porque ahora son los mismos, así que:

 img { width:200px; height: 200px; }

Puede eliminar el div con la clase cat ahora, ya que no es necesario. Y aquí está el código terminado:

 img { width:200px; height: 200px; }
 <!DOCTYPE html> <html> <head> <title>HTML, CSS and JavaScript demo</title> </head> <body> <img src="https://loremflickr.com/400/400" /> </body> </html>

about 4 years ago · Juan Pablo Isaza Report

0

Uso max-width: 100%; significa que cualquiera que sea el tamaño de la imagen, la imagen aparecerá en ella. Cuando el width: 200px está allí, una imagen de cualquier tamaño se mostrará solo en 200 px.

 .cat { width: 300px; height: 300px; } img { width: 300px; height: 300px; }
about 4 years ago · Juan Pablo Isaza Report

0

Las imágenes tienen width y height diferentes por defecto. Por lo tanto, debe especificar los valores de ellos. p.ej:

 .cat { width:200px; height: 500px; border: solid; } img{ width: 100%; height: 100%; } .item { width: 100%; height: 50%; }
 <!DOCTYPE html> <html> <head> <title>HTML, CSS and JavaScript demo</title> </head> <body> <div class="cat"> <div class="item"><img src="https://loremflickr.com/400/400" /></div> <div class="item"><img src="https://s4.uupload.ir/files/5c29cf910a706_8m.jpg" /></div> </div> </body> </html>

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!