1. 程式人生 > >滑鼠放上圖片,圖片上方出現遮罩和文字效果

滑鼠放上圖片,圖片上方出現遮罩和文字效果

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        .img-box {
            width: 100px;
            height: 100px;
            display
: inline-block
; position: relative; cursor: pointer; }
.img-box img { width: 100%; height: 100%; } .img-box::before, .img-box::after { z-index: 1000; opacity: 0; } .img-box::before { content
: " "
; border: 50px solid #000; position: absolute; }
.img-box::after { content: attr(data-tip); top: -100%; color: #ffffff; position: relative; } .img-box:hover::before { opacity: 0.5; }
.img-box:hover::after { opacity: 1; }
</style> </head> <body> <div class="img-box" data-tip="床前明月光,疑是地上霜。舉頭望明月,低頭思故鄉。"> <img src="1.png"> </div> </body> </html>

前面寫的程式碼有點問題,當時只是用google瀏覽器測了一下就發了,沒想到火狐上有問題,所以就修改了一下,google、firefox和ie都每問題,不過data-tip中的文字不能太多,如果太多會溢位圖片遮罩,這個可以根據具體情況優化一下。