How to make images adapt to screen size in css

王林
Release: 2020-11-30 11:37:53
Original
23815 people have browsed it

css让图片自适应屏幕大小的方法:在css文件中加入代码【img {height: auto; width: auto\9; width:100%;}】即可。如果我们只想更改特定的图片,那么可以使用方法【height: auto;】。

How to make images adapt to screen size in css

本教程操作环境:windows10系统、css3,本文适用于所有品牌的电脑。

如果想让图片自适应屏幕的大小,那么在css代码里加入如下代码即可

(学习视频分享:java视频教程

img {height: auto; width: auto\9; width:100%;}
Copy after login

用max-width设置,如果图片尺寸大于当前浏览器尺寸就自动缩放,图片的高度设置正比缩放。

height:auto,相关元素的高度取决于浏览器。

代码如下:

响应式图像
Copy after login

如果只想改特定的图片

.img-responsive { display: inline-block; height: auto; max-width: 100%; }
Copy after login

相关推荐:CSS教程

The above is the detailed content of How to make images adapt to screen size in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!