我如何用CSS替换文本使用这样的方法:

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

而不是(img[src*="IKON. "img"]),我需要使用一些可以代替文本的东西。

我必须使用[]才能让它工作。

< div级= >事实“pvw-title < / div >

我得把"事实"替换掉。


当前回答

我找到了一个这样的解决方案,在较小的屏幕宽度上,一个单词“Dark”将被缩短为“D”。基本上,您只需使原始内容的字体大小为0,并将缩短的形式作为伪元素。

在这个例子中,改变发生在hover上:

跨度{ 字体大小:12 px; } 跨度:{后 显示:没有; 字体大小:12 px; 内容:' D '; 颜色:红色; } 跨度:{徘徊 字体大小:0 px; } 跨度:徘徊:{后 显示:内联; } 黑暗< span > < / span >

其他回答

这适用于我的内联文本。它在Firefox、Safari、Chrome和Opera上进行了测试。

<p>Lorem ipsum dolor sit amet, consectetur <span>Some Text</span> adipiscing elit.</p>

span {
    visibility: hidden;
    word-spacing: -999px;
    letter-spacing: -999px;
}

span:after {
    content: "goodbye";
    visibility: visible;
    word-spacing: normal;
    letter-spacing: normal;
}

与我在其他每个答案中看到的不同,您不需要使用伪元素来将标记的内容替换为图像

<div class="pvw-title">Facts</div>

    div.pvw-title { /* No :after or :before required */
        content: url("your URL here");
    }

为了在使用后隐藏原始内容,你可以使用这个hack:

.pvw-title { 字体大小:0; } .pvw-title:{后 字体大小:1快速眼动; 内容:“我是一段完全不同的文字!”; } < div class = " pvw-title”>事实< / div >

将font-size设置为0会使文本消失,而不会从视口中移除实际的元素。因此,:after选择器可以工作,并且应该在所有浏览器上显示。

文本替换伪元素和CSS可见性

HTML

<p class="replaced">Original Text</p>

CSS

.replaced {
    visibility: hidden;
    position: relative;
}

.replaced:after {
    visibility: visible;
    position: absolute;
    top: 0;
    left: 0;
    content: "This text replaces the original.";
}

例子

<!DOCTYPE html>
<html> 
<head> 
   <title>Devnote</title>
    <style>
        .replacedValue { 
            visibility: hidden; 
            position: relative; 
        } 
        .replacedValue:after { 
            visibility: visible; 
            position: absolute; 
            top: 0; 
            left: 0; 
            content: "Devnote is developer answer solve. devnote.in"; 
        } 
    </style> 
</head>
<body> 
    <p class="replacedValue">Old Text Here</p>
</body> 
</html>

输出

Devnote is developer answer solve. devnote.in