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

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

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

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

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

我得把"事实"替换掉。


当前回答

如果您愿意使用伪元素并让它们插入内容,您可以执行以下操作。它不假设原始元素的知识,也不需要额外的标记。

.element {
  text-indent: -9999px;
  line-height: 0; /* Collapse the original line */
}

.element::after {
  content: "New text";
  text-indent: 0;
  display: block;
  line-height: initial; /* New content takes up original line height */
}

JSFiddle例子

其他回答

基于 mikemaccana的回答, 这对我很有效

按钮{ 位置:绝对的; 可见性:隐藏; } 按钮:{之前 内容:“再见”; 可见性:可见; } 原来<按钮> < / >按钮

§绝对定位

绝对定位的元素将从流中取出,从而 放置其他元素时不占用空间。

试着使用:before和:after。一个在HTML呈现之后插入文本,另一个在HTML呈现之前插入文本。如果要替换文本,请将按钮内容保留为空。

这个例子根据屏幕宽度的大小设置按钮文本。

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>
  button:before {
    content: 'small screen';
  }
  @media screen and (min-width: 480px) {
    button:before {
      content: 'big screen';
    }
  }
</style>
<body>
  <button type="button">xxx</button>
  <button type="button"></button>
</body>

按钮的文本:

之前: 大screenxxx 大屏幕 后: xxxbig屏幕 大屏幕

八年后,当我试图使用Stylish浏览器扩展来更改一个网站(不是我的)上的某些内容时,我遇到了同样的挑战。这一次,我通过使用“inspect element”查看源代码,并基于此创建CSS代码,使其工作。

这是它以前的样子:

< table > < tbody > < tr > < td gridcell”角色= > <span标题=“在进展中”风格=“背景”右方:2px;text-align: center;width: 45px;显示:区块;超流:隐藏;文本overflow: ellipsis;“>进行中< /跨越> < / td > < / tr > < / tbody > - < table >

这是我用来修改样式的HTML和CSS的同一部分:

td span[style="background-color: #e2047a;color:White;margin:2px;border-radius:2px;padding-left: 2px; padding-right: 2px;text-align: center;width: 45px; display: block;overflow: hidden;text-overflow: ellipsis;"] { width: 100px!important; } <table> <tbody> <tr> <td role="gridcell"> <span title="In progress" style="background-color: #e2047a;color:White;margin:2px;border-radius:2px;padding-left: 2px; padding-right: 2px;text-align: center;width: 45px; display: block;overflow: hidden;text-overflow: ellipsis;">In progress</span> </td> </tr> </tbody> </table>

你可以运行上面的代码,你会看到它工作(在Chrome测试)。


这就是我当初问这个问题时想要的结果。

我使用一些社区博客/Myspace类似的东西,当你的个人资料的样式是他们的CSS编辑器时,你唯一拥有的东西,这就是为什么我想根据风格选择它。

我在这里找到了答案:

高级CSS选择器-根据样式选择 CSS选择器的内联样式属性

这实现了一个复选框作为按钮,根据它的“checked”状态显示Yes或No。因此,它演示了一种使用CSS替换文本的方法,而无需编写任何代码。

在返回(或不返回)POST值时,它仍然表现得像一个复选框,但从显示的角度来看,它看起来像一个切换按钮。

这些颜色可能不是你喜欢的,它们只是为了说明一个观点。

HTML是:

<input type="checkbox" class="yesno" id="testcb" /><label for="testcb"><span></span></label>

...CSS为:

/* --------------------------------- */
/* Make the checkbox non-displayable */
/* --------------------------------- */
input[type="checkbox"].yesno {
    display:none;
}
/* --------------------------------- */
/* Set the associated label <span>   */
/* 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 <span> is "No"          */
/* --------------------------------- */
input[type="checkbox"].yesno+label span:after {
    content:"No";
}
/* --------------------------------- */
/* When the box is checked the       */
/* content after the label <span>    */
/* 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 <span> 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;
}

我只在Firefox上尝试过,但它是标准的CSS,所以它应该在其他地方工作。

试试这个方法:

IDENTIFIER {
    visibility: hidden;
    position: relative;
}
IDENTIFIER::after {
    visibility: visible;
    position: absolute;
    top: 0;
    left: 0;
    content: "NEW_CONTENT";
}