CSS 奇技淫巧

原型头像(带非正方形图片居中功能)


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<style>
.circle-img {
width: 100px;
height: 100px;
overflow: hidden;
float: left;
margin-right: 10px;
margin-top: -4.5px;
border-radius: 50%;
}

.circle-img img {
height: 100%;
transform: translateX(-50%);
margin-left: 50%;
}
</style>


<body>
<div class="circle-img">
<img src="http://www.mathwarehouse.com/geometry/quadrilaterals/parallelograms/images/rectangle/rectangle-plain-b.png">
</div>
</body>

1
2
3
4
5
6
img {
width:100%;
height:100%;
object-fit: cover;
overflow: hidden;
}