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 relationship between Vue and VueComponent

The following case reviews the knowledge points o...

Summary of problems that may occur when using JDBC to connect to Mysql database

First, clarify a few concepts: JDBC: Java databas...

How to implement Docker container self-start

Container auto-start Docker provides a restart po...

Using nginx + fastcgi to implement image recognition server

background A specific device is used to perform i...

A brief introduction to the simple use of CentOS7 firewall and open ports

Overview (official has more detailed description)...

An article to understand the advanced features of K8S

Table of contents K8S Advanced Features Advanced ...

How to deploy Oracle using Docker on Mac

How to deploy Oracle using Docker on Mac First in...

MySQL service and database management

Table of contents 1. Start and stop service instr...

MySql common query command operation list

MYSQL commonly used query commands: mysql> sel...

MySQL configuration SSL master-slave replication

MySQL5.6 How to create SSL files Official documen...

Nexus private server construction principle and tutorial analysis

one. Why build a Nexus private server? All develo...