png格式的img元素直接設置背景色、border-radius等屬性,不需再包裹div形成冗餘

原html結構css

<div class="user-inform">
       <div class="user-img">
              <img src="http://coding.imweb.io/img/project/resume/avatar.png" alt="簡歷頭像">
        </div>
</div>

原css結構html

.user-inform .user-img {
    margin-top: 100px;
    margin-left: auto;
    margin-right: auto;
    width: 120px;
    height: 120px;
    background-color: white;
    border-radius: 50%;
    box-shadow: 0 0 0 5px #88bde8;
}

.user-inform .user-img:hover {
    animation: circleRun 1s ease infinite;
}
@keyframes circleRun {
    0% {
        box-shadow: 0 0 0 5px #88bde8;
    }
    50% {
        box-shadow: 0 0 5px 10px #88bde8;
    }
    100% {
        box-shadow: 0 0 0 5px #88bde8;
    }
}
.user-inform .user-img img{
    position: absolute;
    width: 120px;
    height: 115px;
}

獲得老師的建議是,img是png格式的,因此徹底能夠設置img的背景色,以及border-radius,不須要在外面包裹div來作這些。web

修改後的html結構spa

<div class="user-inform">
        <img src="http://coding.imweb.io/img/project/resume/avatar.png" alt="簡歷頭像">
</div>

修改後的cssl結構code

.user-inform img{
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 5px #88bde8;
}
.user-inform img:hover {
    animation: circleRun 1s ease infinite;
}
@keyframes circleRun {
    0% {
        box-shadow: 0 0 0 5px #88bde8;
    }
    50% {
        box-shadow: 0 0 5px 10px #88bde8;
    }
    100% {
        box-shadow: 0 0 0 5px #88bde8;
    }
}
相關文章
相關標籤/搜索