我如何用CSS替换文本使用这样的方法:
.pvw-title img[src*="IKON.img"] { visibility:hidden; }
而不是(img[src*="IKON. "img"]),我需要使用一些可以代替文本的东西。
我必须使用[]才能让它工作。
< div级= >事实“pvw-title < / div >
我得把"事实"替换掉。
我如何用CSS替换文本使用这样的方法:
.pvw-title img[src*="IKON.img"] { visibility:hidden; }
而不是(img[src*="IKON. "img"]),我需要使用一些可以代替文本的东西。
我必须使用[]才能让它工作。
< div级= >事实“pvw-title < / div >
我得把"事实"替换掉。
当前回答
或者你可以把'Facts'包在<span>上,如下所示:
.pvw-title span { 显示:没有; } .pvw-title:{后 内容:“你想加什么就加什么”; } < div class = " pvw-title " > < span >事实< / span > < / div >
其他回答
如果您只是想显示不同的文本或图像,请保持标记为空,并将内容写入多个数据属性,如<span data-text1="Hello" data-text2="Bye"></span>。 使用一个伪类显示它们:before {content: attr(data-text1)}
现在你有很多不同的方法在它们之间切换。我将它们与媒体查询结合使用,以实现响应式设计方法,将导航的名称更改为图标。
Jsfiddle演示和示例
它可能不能完美地回答这个问题,但它满足了我的需求,也许也满足了其他人的需求。
为了在使用后隐藏原始内容,你可以使用这个hack:
.pvw-title { 字体大小:0; } .pvw-title:{后 字体大小:1快速眼动; 内容:“我是一段完全不同的文字!”; } < div class = " pvw-title”>事实< / div >
将font-size设置为0会使文本消失,而不会从视口中移除实际的元素。因此,:after选择器可以工作,并且应该在所有浏览器上显示。
这实现了一个复选框作为按钮,根据它的“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,所以它应该在其他地方工作。
我发现的最简单的方法是使元素font-size: 0px,然后在创建:后pseudo时用任何字体大小覆盖它。在下面的例子:
.pvw-title {
font-size:0px;
}
.pvw-title:after {
content: "Hello";
font-size:15px !important;
}
我比较幸运地将外部元素的font-size: 0和:after选择器的font-size设置为我需要的任何东西。