Home > Web Front-end > CSS Tutorial > How to use css to make images adapt to the screen?

How to use css to make images adapt to the screen?

藏色散人
Release: 2018-08-06 17:49:18
Original
7016 people have browsed it

本篇文章主要介绍了如何实现css图片自适应屏幕的效果。对于新手来说最简单的方法,即图片写在div里面的背景里。这样就能自适应屏幕大小且不会出现横向的滚动条。

css图片自适应屏幕代码示例如下:

background:url(1.jpg) center no-repeat;
background:url(图片地址) 0 0 no-repeat scroll transparent;background-size:100% 100%;
/* 图片固定在ims里面*/
<div class="ims">
<img style="max-width:100%;overflow:hidden;" src="1.jpg" alt="">
</div>
Copy after login

注:在html里面插入图片,如果想让图片自适应屏幕的小而不是宽高固定不变可以在css代码里加入

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

\9是hack css 的一种写法,这种在正常css代码后面加"\9"的方式,只有IE浏览器才能识别,其他浏览器会忽略这条语句。这样就能做到差异化浏览器,来达到兼容浏览器的目的。

【相关文章推荐】

响应式和自适应有什么区别

怎样实现图片大小自适应 

padding制作图片自适应布局(CSS百分比)

HTML中使背景图片自适应浏览器大小


The above is the detailed content of How to use css to make images adapt to the screen?. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template