1. Use the transform attribute to display the image without stretching (the path problem needs to be modified as required); html: <div id="surface-div1"> <img :src="pic1" class="surface-img"> </div> CSS: #surface-div1{ position: relative; width: 372px; height: 175px; float: left; margin-top: -34px; margin-left: 122px; cursor: pointer; background: url(../../../static/img/addheadpic.jpg)center center no-repeat; text-align: center; border: 1px solid #CCCCCC; border-radius:6px; overflow: hidden; } #surface-div1 img{ position: absolute; width: 100%; top: 50%; left: 0; transform: translateY(-50%) scale(1); border:none; border-radius: 6px;display:table-cell } The final effect is shown on the left side of the picture above. 2. Refer to Taobao and use display:table-cell and text size to control the center html: <div id="surface-div"> <div class="sur-div"> <img :src="pic" class="surface-img"> </div> </div> css: #surface-div{ position: relative; width: 372px; height: 372px; float: left; margin-top: -34px; margin-left: 122px; cursor: pointer; background: url(../../../static/img/addheadpic.jpg)center center no-repeat; text-align: center; border: 1px solid #CCCCCC; border-radius:6px; overflow: hidden; } .sur-div{ display: table-cell; text-align: center; vertical-align: middle; font-size: 12px; width: 372px; height: 372px; overflow: hidden; } #surface-div img{ max-height: 100%; max-width: 100%; vertical-align: middle; border: 0; } The effect is as shown on the left side of the picture above. The key point is that the outer div needs to be a square. This is the end of this article about the display effect of html css3 non-stretched images. For more relevant html css3 non-stretched images content, please search 123WORDPRESS.COM’s previous articles or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! |
<<: HTML+CSS to create a top navigation bar menu
>>: Problems with creating placeholders for HTML selection boxes
Abstract: MySQL provides a variety of storage eng...
1. Review The Buffer Pool will be initialized aft...
First of all, we need to make it clear why we use...
How to install and configure mysql-5.7.5-m15-winx...
Six steps to install MySQL (only the installation...
Nowadays, whether you are on the sofa at home or ...
We better start paying attention, because HTML Po...
Let’s install Nginx and try it out. Please note t...
Long story short, today we will talk about using ...
1. Brief Introduction of Nginx Nginx is a free, o...
1 Introduction to HTML 1.1 First experience with ...
XML/HTML CodeCopy content to clipboard < div c...
HTML web page hyperlink tag learning tutorial lin...
HTML stands for Hypertext Markup Language. Nowada...
background If the catalina.out log file generated...