一同事应聘TX,出了一道题,分别用1,2,3,5个标签实现红十字会图标,图标水平、垂直居中,短边50px,长边150px。如图:
其中用2,3,5个标签实现不难,略过。一个标签的我比较有兴趣,午休时间想了下,睡醒后就动手实现,代码如下:
div{
width: 150px;
height: 50px;
background: red;
position: absolute;
top: 50%;
left: 50%;
margin-left: -75px;
margin-top: -25px;
}
div:before{
border-color: red;
border-style: solid;
border-width: 75px 25px;
content: "";
left: 50%;
margin-left: -25px;
position: absolute;
top: -50px;
}