SOURCE

console 命令行工具 X clear

                    
>
console
<h3>基于变形的方案</h3>
<div class="diamond-1">
    <img src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2037859021,4051808186&fm=26&gp=0.jpg" alt="">
</div>

<h3>裁切路径方案</h3>
<img class="diamond-2" src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2037859021,4051808186&fm=26&gp=0.jpg" alt="">


*{
    padding:0;
    margin:0;
    box-sizing: border-box;
}
body {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}
h3 {
    align-self: flex-start;
    margin-bottom: 20px;
}

h3:not(:first-child) {
    margin-top: 20px;
}
/* 基于变形的方案 */
.diamond-1 {
    width: 200px;
    height: 200px;
    background-color: yellow;
    overflow: hidden;
    /* 以下为重要代码 */
    transform: rotate(45deg);
}
.diamond-1>img {
    /* 以下为重要代码 */
    max-width: 100%;
    transform: rotate(-45deg) scale(1.42);
}

/* 裁切路径方案 */
.diamond-2 {
    width: 200px;
    height: 200px;
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

.diamond-2:hover {
    clip-path: polygon(0 0, 100% 0,
    100% 100%, 0 100%);
}