原图:
Home > Web Front-end > JS Tutorial > JS CSS sets img to display only the vertically centered part of Img in DIV_javascript tips

JS CSS sets img to display only the vertically centered part of Img in DIV_javascript tips

WBOY
Release: 2016-05-16 17:19:07
Original
1012 people have browsed it

Img is displayed in a Div. The width of img is the same as that of Div, but the height is not fixed. It is required that only the vertically centered part of Img be displayed.

Example:
JS CSS sets img to display only the vertically centered part of Img in DIV_javascript tips

Original image:
JS CSS sets img to display only the vertically centered part of Img in DIV_javascript tips

Code implementation:

Copy code The code is as follows:


onload="this.style.marginTop = (parseInt(this.parentNode.style.height) - this.height)/2 'px';this.style.marginLeft = (parseInt(this.parentNode.style.width) - this.width) /2 'px'" />


Click to download the source file
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