html - 响应式图像代码未获取适当分辨率的图像
问题描述
尝试对我的英雄形象使用响应式尺寸。一切看起来应该如何并且排列正确,但我注意到无论浏览器的宽度是多少,它总是抓取相同(最低质量)的图像。我通过调整屏幕大小、右键单击并选择“在新选项卡中打开图像”来检查这一点,然后在那里检查分辨率。
屏幕分辨率为 1366x768 Browser is Brave (Chromium) 图像分辨率列在文件名中
我希望你能找出问题所在。
<head>
<meta charset='UTF-8' />
<title>Title</title>
<link rel='stylesheet' href='styles.css' />
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0' />
</head>
<body>
<div class='page'>
<div class='menu'>
</div>
<div class='section hero-image'>
<div class='photo'>
<picture>
<source media='(min-width: 601px)' srcset='images/Dam-Hero-image 1959x1306.jpg'/>
<source media='(max-width: 600px)' srcset='images/Dam-Hero-image 800x1100.jpg'/>
<img src='images/Dam-Hero-image 980x653.jpg'/>
</picture>
</div>
</div>
/* Page styles */
.page {
display: flex;
flex-wrap: wrap;
}
/* Hero styles */
.hero-image {
height: auto;
justify-content: inherit;
align-items: inherit;
}
.photo img {
width: 100%;
display: block;
}
/* Mobile Styles */
@media only screen and (max-width: 600px) {
.hero-message {
width: 100%;
}
}
/* Tablet Styles */
@media only screen and (min-width: 601px) and (max-width: 960px) {
}
/* Desktop Styles */
@media only screen and (min-width: 961px) {
.page {
width: 960px;
}
}
It should change the image being used when the browser crosses the given pixel threshold, but I suppose its something else like the images are too big or the browser needs to be refreshed each time (although I've tried this already). Thanks for your help!
解决方案
.photo img {
width: 100%;
display: block;
也许你的问题是.photo img {
......我想你想要.photo, img {
编辑:
我刚刚注意到你有@media only screen
. 我认为它应该是,简单地说, @media screen
。
推荐阅读
- javascript - 如何在 Javascript 中增加每小时使用 Github API 的限制
- c# - HttpContext.RequestServices.GetService
() 与 services.AddScope ()? - aws-api-gateway - 无法在 AWS 控制台中创建 API 管理 VPC 链接
- angular - Angular:我应用网格选项后,ag-grid 正在重置
- amazon-web-services - Amazon MTurk:无法删除处于“可审查”状态的 HIT
- math - 从任意角度的两个点计算等边三角形的第三个点,为科赫雪花指出“正确”的方式
- javascript - 为什么这不是javascript中的数组?
- sql - MS Access 使用 VBA 插入数据,运行时错误 3061
- html - flex.sm vs flex.md vs fxFlex.lg 和 fxFlex.gt-lg 等有什么区别?
- python - socket.sock().bind() 地址已经在使用中