set image size with respect to the screen resolution

假装没事ソ 提交于 2019-12-04 09:46:45

If you only specify the width in css, the height will scale automatically. You can easily specify the with of the image relative to its parent.

In your example you would have to specify width: 27% (1280 / 350). Note that the parent will have to be 100% wide.

You can get the screen size from the DOM using screen.width and screen.height. Then you can write some JS to load or replace with the desired image or adjust the height/width attributes on the image (which would scale it, but doesn't always look great).

There is a good article on fluid grids by Ethan Marcotte, http://www.alistapart.com/articles/fluidgrids/

You can apply these principals to your images using CSS, he does on his personal site. There even good apps to help you out.

this one has a read me -> web duck http://inteldesigner.com/web-duck/about.php

this one has more features -> em calc http://riddle.pl/emcalc/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!