Home  >  Article  >  Web Front-end  >  html中怎么把图片按比例缩放在<span>里面_html/css_WEB-ITnose

html中怎么把图片按比例缩放在<span>里面_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 12:08:591539browse

我在中放一个背景图片,当图片过大就会显示一部分出来,过小的时候会自动居中。请问怎么设置才会让图片不管过大还是过小都全部显示。 求指点下。


回复讨论(解决方案)

百度一个图片垂直横向居中显示的就行了

给图片一个指定的宽度。

1.给图片设置固定宽和高
2.用js控制图片大小,小于设定就按原尺寸,大于则由js按比例调整合适

你在span里面写的需要给span写上宽高 display:block; overflow:hidden;

用jquery,如果宽度大于最大值,就将图片宽度设置成最大宽度值,然后用jquery去实现,高度=实际高度/(实际宽度/最大宽度)

Statement:
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