Home > Web Front-end > HTML Tutorial > The img in the div is displayed in the center according to different resolutions, and the excess part is hidden_html/css_WEB-ITnose

The img in the div is displayed in the center according to different resolutions, and the excess part is hidden_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:49:54
Original
1580 people have browsed it

Use div to control the center display of the img image in the div. As shown below, the yellow area is a 1920*300 image. If the resolution exceeds 1920, it will be fully displayed in the center. If the resolution is 1440, it will display the green color in the yellow image. The area size is displayed in the center. If the resolution is 1024, the yellow image will be displayed as large as the pink area in the center.
The code format should be

. Do not set a background image for the div. It is compatible with IE Google Chrome


Reply to the discussion (solution)

<div><img src="http://avatar.csdn.net/B/5/B/1_z549903832.jpg"/></div><style>  div{width:50px;height:200px;background:red;position:relative;overflow:hidden;}  img{margin:-50px 0px 0px -50px/*img宽度高度的一半*/;top:50%;left:50%;position:absolute;}</style>
Copy after login

The code format should be

, do not set a background image for the div Yes, compatible with IE Google Chrome



Background centered Is there any incompatible browser?
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