HTML响应图像大小

时间:2017-09-29 01:08:52

标签: html css image

我有一张640*225图片,我想让它适合各种设备屏幕, 当我放width="100%"它完全适合小型设备但在PC上它会延伸,直到它适合整个浏览器宽度。 有没有办法在大屏幕上设置实际图像大小,并在它达到宽度尺寸图像时响应?

2 个答案:

答案 0 :(得分:0)

您可以使用媒体查询为每个屏幕分辨率指定自定义样式。其中最受欢迎的是我在下面的片段中添加的内容:



/*==========  Desktop First Method  ==========*/

/* Large Devices, Wide Screens */
@media only screen and (max-width : 1200px) {

}

/* Medium Devices, Desktops */
@media only screen and (max-width : 992px) {

}

/* Small Devices, Tablets */
@media only screen and (max-width : 768px) {

}

/* Extra Small Devices, Phones */
@media only screen and (max-width : 480px) {

}

/* Custom, iPhone Retina */
@media only screen and (max-width : 320px) {

}


/*==========  Mobile First Method  ==========*/

/* Custom, iPhone Retina */
@media only screen and (min-width : 320px) {

}

/* Extra Small Devices, Phones */
@media only screen and (min-width : 480px) {

}

/* Small Devices, Tablets */
@media only screen and (min-width : 768px) {

}

/* Medium Devices, Desktops */
@media only screen and (min-width : 992px) {

}

 /* Large Devices, Wide Screens */
@media only screen and (min-width : 1200px) {

}




有关媒体查询的更多信息:

  1. https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
  2. https://www.w3schools.com/css/css_rwd_mediaqueries.asp

答案 1 :(得分:0)

尝试width:100%; max-width:80%;