How to change content on hover

前端 未结 4 1280
走了就别回头了
走了就别回头了 2020-11-29 05:01

I\'ve been playing around with this, and I thought it would be pretty simple. What I\'m trying to do is hover over the \'NEW\' label. Once in its hover state, change the con

4条回答
  •  半阙折子戏
    2020-11-29 05:28

    This exact example is present on mozilla developers page:

    ::after

    As you can see it even allows you to create tooltips! :) Also, instead of embedding the actual text in your CSS, you may use content: attr(data-descr);, and store it in data-descr="ADD" attribute of your HTML tag (which is nice because you can e.g translate it)

    CSS content can only be usef with :after and :before pseudo-elements, so you can try to proceed with something like this:

    .item a p.new-label span:after{
      position: relative;
      content: 'NEW'
    }
    .item:hover a p.new-label span:after {
      content: 'ADD';
    }
    

    The CSS :after pseudo-element matches a virtual last child of the selected element. Typically used to add cosmetic content to an element, by using the content CSS property. This element is inline by default.

提交回复
热议问题