How can I replace text with CSS?

前端 未结 21 2176
暗喜
暗喜 2020-11-22 06:17

How can I replace text with CSS using a method like this:

.pvw-title img[src*=\"IKON.img\"] { visibility:hidden; }

Instead of ( img

21条回答
  •  无人及你
    2020-11-22 07:11

    Obligatory: This is a hack: CSS isn't the right place to do this, but in some situations - eg, you have a third party library in an iframe that can only be customized by CSS - this kind of hack is the only option.

    You can replace text through CSS. Let's replace a green button that has the word 'hello' with a red button that has the word 'goodbye', using CSS.

    Before:

    After:

    See http://jsfiddle.net/ZBj2m/274/ for a live demo:

    Here's our green button:

    
    
    button {
      background-color: green;
      color: black;
      padding: 5px;
    }
    

    Now let's hide the original element, but add another block element afterwards:

    button {
      visibility: hidden;
    }
    button:after {
      content:'goodbye'; 
      visibility: visible;
      display: block;
      position: absolute;
      background-color: red;
      padding: 5px;
      top: 2px;
    }
    

    Note:

    • We explicitly need to mark this as a block element, 'after' elements are inline by default
    • We need to compensate for the original element by adjusting the pseudo-element's position.
    • We must hide the original element and display the pseudo element using visibility. Note display: none on the original element doesn't work.

提交回复
热议问题