【发布时间】:2018-03-06 05:05:50
【问题描述】:
我想使用 HTML 和 CSS 更改图像,使其大小符合屏幕分辨率,例如 1920x1080 到 1600x900。
我该怎么做?
【问题讨论】:
标签: html css image screen-resolution
我想使用 HTML 和 CSS 更改图像,使其大小符合屏幕分辨率,例如 1920x1080 到 1600x900。
我该怎么做?
【问题讨论】:
标签: html css image screen-resolution
使用媒体查询。这仅适用于相关的屏幕分辨率
@media only screen and (min-width: 1490px)
{
}
@media only screen and (max-width: 1490px) and (min-width: 1366px)
{
}
@media only screen and (max-width: 1366px) and (min-width: 1280px)
{
}
@media only screen and (max-width: 1280px) and (min-width: 1024px)
{
}
@media only screen and (max-width: 1024px) and (min-width: 768px)
{
}
【讨论】:
HTML:
<div class="img-div">
<img src="path-to-image">
</div>
CSS:
.img-div { height:100%; width:100%;}
img { max-width:100% }
【讨论】:
您可以使用@media 规则或以百分比设置图像大小。
【讨论】:
HTML
<img src="path of the image" alt="any message you want to type">
CSS
img {width: 15%; height: any numberpx;}
// 确保您以百分比形式给出图像的宽度,这将根据您可以根据需要提供的屏幕高度的大小调整您的图像。
【讨论】: