Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
306 views
in Technique[技术] by (71.8m points)

html - Can I use srcset with inaccurate image widths?

I have a centralized function to generate image tags:

function getSrcAndSrcSet($img) {
        $src="/img/init/$img";
        $srcset="/img/low/$img 100w, /img/medium/$img 800w, /img/high/$img 1200w";
        return 'src="'.$src.'" srcset="'.$srcset.'"';
    }

Various images of varying sizes might be passed to the function, most likely none of them are exactly 100px, 800px or 1200px in width.

  1. Does it matter that the widths are inaccurate, or does it just mean that the decision on image is based on that number rather than the real image size?

  2. Is there a way to create a srcset such that the decision is made on if a screen is a certain size (as opposed to the specific image will be a certain size)? For CSS background images I can use a media query, can I use that here? I don't think I can use the sizes attribute because I don't know what the specific image sizes will be when the function is invoked.

question from:https://stackoverflow.com/questions/65847553/can-i-use-srcset-with-inaccurate-image-widths

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...