CSS: before / after content with title

后端 未结 3 1560
面向向阳花
面向向阳花 2020-12-18 18:49

I can do

div:after {
  content: \"hello\"
}

But can I have the hello text with a title so that when I hover it with the mouse

3条回答
  •  清酒与你
    2020-12-18 19:37

    You don't need a pseudo-element for that:

    p {
        background:lightblue;
        padding:15px;
        margin:15px;
    }

    Some Text

    However, if you need to use a pseudo element

    p {
        background:lightblue;
        padding:15px;
        margin:15px;
        position: relative;
    }
    
    p:hover:after {
        position: absolute;
        content:attr(data-title);
        left:0;
        top:0;
        width:200px;
        height:1.25rem;
        background-color: blue;
        color:white;
    }

    Some Text

提交回复
热议问题