[Mobile Web] LEVEL 5 RESPONSIVE MEDIA -- Ex
MAX-WIDTH
Set the max-width
of images
to 100%
.
img{ max-width: 100%; }
MAX-WIDTH ON ASSETS
Set the max-width
of images
, embeds
, objects
, and videos
to 100%
.
img, embed, object, video{ max-width: 100%; }
MEDIA QUERY #1
Write a media query
to target devices with a at least a 1.5
device-pixel-ratio
, using the screen
media type. Make sure to target the -webkit
proprietary extension, as well.
@media
only screen and (-webkit-min-device-pixel-ratio: 1.5),
only screen and (min-device-pixel-ratio: 1.5){
}
MEDIA QUERY #2
Assuming we have a 75px by 75px
logo.png image and a high-resolutionlogo@2x.png
image, include the high-resolution image within the media query you just wrote as a background-image
on the .logo
. Don't forget to set the background-size
as well.
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-device-pixel-ratio: 1.5) { .logo { background-image: url('logo@2x.png'); -webkit-background-size: 75px 75px; background-size: 75px 75px; } }
PICTURE ELEMENT
Using the Scott Jehl PictureFill method, create a <picture>
element with "Our Camp Site" as the alt
text. Also add camp-site.jpeg
as the smallest source size, with no @media qualifier.
<picture alt="Our Camp Site">
<source src="camp-site.jpeg" />
</picture>
MEDIA SPECIFIC IMAGES
Now, add camp-site-lrg.jpeg
as the second source, with an @media
qualifier for devices with a width of at least 900px
.
<picture alt="Our Camp Site">
<source src="camp-site.jpeg" />
<source src="camp-site-lrg.jpeg" media="(min-width:900px)"/>
</picture>
NOSCRIPT FALLBACK
Finally, add a <noscript>
fallback block within the <picture>
element to include a normal img
tag, with the camp-site.jpeg and "Our Camp Site" alt text.
<picture alt="Our Camp Site">
<source src="camp-site.jpeg" />
<source src="camp-site-lrg.jpeg" media="(min-width: 900px)" />
<noscript>
<img src="camp-site.jpeg" alt="Our Camp Site" />
</noscript>
</picture>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具