una tamaño mostrar insertar imagen estilo ejemplo codigo cambiar atributo html css responsive-design media-queries image-gallery

html - mostrar - Detener el cambio de tamaño de las imágenes en código css



mostrar imagen en html (2)

Tengo el siguiente código crear una galería de imágenes. Debe ser receptivo. Pero los problemas, cuando cambia el ancho de la ventana, las imágenes cambian de tamaño. Perderá la relación de aspecto. Cualquier forma de arreglar esto. Soy nuevo en la codificación css

* { padding: 0; margin: 0; } /*HEADER STYLES*/ .header { width: 80%; margin: 30px auto; overflow: hidden; } .word:hover{ opacity: 0.9; -webkit-transition: all .5s ease; -moz-transition: all .5s ease; -o-transition: all .5s ease; -ms-transition: all .5s ease; transition: all .5s ease; } .word { -webkit-transition: all .5s ease; -moz-transition: all .5s ease; -o-transition: all .5s ease; -ms-transition: all .5s ease; transition: all .5s ease; border-radius: 5px; background:url(huzup.jpg); background-size:100% 100%; background-repeat:no-repeat; color:white; font-size:20px; font-family: ''Russo One'', sans-serif; height:100PX; width:180PX; text-align:center; border:1px solid silver; display: table-cell; vertical-align:middle; } .container { width: 80%; margin: 30px auto; overflow: hidden; } /*GALLERY STYLES*/ .galleryItem { color: #797478; font: 10px/1.5 Verdana, Helvetica, sans-serif; width: 16%; margin: 2% 2% 50px 2%; float: left; -webkit-transition: color 0.5s ease; } .galleryItem h3 { text-transform: uppercase; line-height: 2; } .galleryItem:hover { color: #000; } .galleryItem img { max-width: 100%; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; } /* MEDIA QUERIES*/ @media only screen and (max-width : 940px), only screen and (max-device-width : 940px){ .galleryItem {width: 21%;} } @media only screen and (max-width : 720px), only screen and (max-device-width : 720px){ .galleryItem {width: 29.33333%;} .header h1 {font-size: 40px;} } @media only screen and (max-width : 530px), only screen and (max-device-width : 530px){ .galleryItem {width: 46%;} .header h1 {font-size: 28px;} } @media only screen and (max-width : 320px), only screen and (max-device-width : 320px){ .galleryItem {width: 96%;} .galleryItem img {width: 96%;} .galleryItem h3 {font-size: 18px;} .galleryItem p, .header p {font-size: 18px;} .header h1 {font-size: 70px;} }


Para mantener la relación de aspecto para imágenes receptivas, puede usar height: auto. Por ejemplo:

img { width:100%; height:auto }


img { max-width: 100%; height: auto; width: auto/9; /* ie8 */ }

y luego cualquier imagen que agregue simplemente usando la etiqueta img será flexible

Para hacer que las imágenes sean flexibles, simplemente agregue max-width: 100% y height: auto . max-width:100% imagen max-width:100% y height:auto funciona en IE7, pero no en IE8 (sí, otro error raro de IE). Para solucionar esto, necesita agregar width:auto/9 para IE8.

Puede ver la demostración sobre el mantenimiento de las relaciones de aspecto de la imagen. Ver demostración