How can I replace text with CSS?

前端 未结 21 2207
暗喜
暗喜 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:05

    This implements a checkbox as a button which shows either Yes or No depending on its 'checked' state. So it demonstrates one way of replacing text using CSS without having to write any code.

    It will still behave like a checkbox as far as returning (or not returning) a POST value, but from a display point of view it looks like a toggle button.

    The colours may not be to your liking, they're only there to illustrate a point.

    The HTML is:

    
    

    ...and the CSS is:

    /* --------------------------------- */
    /* Make the checkbox non-displayable */
    /* --------------------------------- */
    input[type="checkbox"].yesno {
        display:none;
    }
    /* --------------------------------- */
    /* Set the associated label    */
    /* the way you want it to look.      */
    /* --------------------------------- */
    input[type="checkbox"].yesno+label span {
        display:inline-block;
        width:80px;
        height:30px;
        text-align:center;
        vertical-align:middle;
        color:#800000;
        background-color:white;
        border-style:solid;
        border-width:1px;
        border-color:black;
        cursor:pointer;
    }
    /* --------------------------------- */
    /* By default the content after the  */
    /* the label  is "No"          */
    /* --------------------------------- */
    input[type="checkbox"].yesno+label span:after {
        content:"No";
    }
    /* --------------------------------- */
    /* When the box is checked the       */
    /* content after the label     */
    /* is "Yes" (which replaces any      */
    /* existing content).                */
    /* When the box becomes unchecked the*/
    /* content reverts to the way it was.*/
    /* --------------------------------- */
    input[type="checkbox"].yesno:checked+label span:after {
        content:"Yes";
    }
    /* --------------------------------- */
    /* When the box is checked the       */
    /* label  looks like this      */
    /* (which replaces any existing)     */
    /* When the box becomes unchecked the*/
    /* layout reverts to the way it was. */
    /* --------------------------------- */
    input[type="checkbox"].yesno:checked+label span {
        color:green;
        background-color:#C8C8C8;
    }
    

    I've only tried it on Firefox, but it's standard CSS so it ought to work elsewhere.

提交回复
热议问题