HTML CSS3 does not stretch the image display effect

HTML CSS3 does not stretch the image display effect

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.
Taobao's is like this:

這里寫圖片描述

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

Recommend

Detailed explanation of the syntax and process of executing MySQL transactions

Abstract: MySQL provides a variety of storage eng...

MySQL Flush-List and dirty page flushing mechanism

1. Review The Buffer Pool will be initialized aft...

MySql implements page query function

First of all, we need to make it clear why we use...

mysql 5.7.5 m15 winx64.zip installation tutorial

How to install and configure mysql-5.7.5-m15-winx...

MySQL 8.0.21 free installation version configuration method graphic tutorial

Six steps to install MySQL (only the installation...

Linux uses NetworkManager to randomly generate your MAC address

Nowadays, whether you are on the sofa at home or ...

Common HTML tag writing errors

We better start paying attention, because HTML Po...

Docker installation Nginx tutorial implementation illustration

Let’s install Nginx and try it out. Please note t...

Nginx installation detailed tutorial

1. Brief Introduction of Nginx Nginx is a free, o...

Introduction to HTML for front-end developers

1 Introduction to HTML 1.1 First experience with ...

Select does not support double click dbclick event

XML/HTML CodeCopy content to clipboard < div c...

HTML web page hyperlink tag

HTML web page hyperlink tag learning tutorial lin...

What is html file? How to open html file

HTML stands for Hypertext Markup Language. Nowada...

Tomcat8 uses cronolog to split Catalina.Out logs

background If the catalina.out log file generated...