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
The following case reviews the knowledge points o...
First, clarify a few concepts: JDBC: Java databas...
Container auto-start Docker provides a restart po...
mysql-8.0.19-winx64 downloaded from the official ...
Install the unzipped version of MySql database un...
background A specific device is used to perform i...
The environment of this article is Windows 10, an...
Overview (official has more detailed description)...
Table of contents K8S Advanced Features Advanced ...
What products do you want to mention? Recently, t...
How to deploy Oracle using Docker on Mac First in...
Table of contents 1. Start and stop service instr...
MYSQL commonly used query commands: mysql> sel...
MySQL5.6 How to create SSL files Official documen...
one. Why build a Nexus private server? All develo...