html - 使用 CSS 时是否可以只定位::before 和::after 之间的内容?

标签 html css

我无法访问 JavaScript 或 HTML,只能访问 CSS。

我正在尝试将已经存在的文本更改为其他内容。

#element::before {
  content: "This is the new text."
}
<div id="element">This is the original text.</div>

是否可以使用 CSS 专门针对旧文本,然后应用 text-indent: -9999px;

最佳答案

无法专门针对元素的文本节点;见Is there a CSS selector for text nodes?获取更多信息。

您可以通过多种方式实现您想要的效果,但正如 Paulie_D 所建议的那样,这是否是一个好主意取决于您要实现的目标。

#element {
    visibility: hidden;
}
#element:before {
    content:"My new text using visibilty.";
    visibility: visible;
}
#element2 {
    font-size: 0;
}
#element2:before {
    content:"My new text using font-size.";
    font-size: 16px;
}
<div id="element">This is the original text.</div>
<div id="element2">This is the original text.</div>

关于html - 使用 CSS 时是否可以只定位::before 和::after 之间的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26651723/

相关文章:

javascript - CSS 无法对 Knockout 绘制的表格应用 dark-stripe 和 light-stripe

jquery - Webkit CSS 动画跳转问题

css - Highchart Angular 溢出容器

html - "a"标签被复制并应用到附近的文本——为什么?

javascript - 在Bootstrap3中,单击按钮使一个div显示而另一个div隐藏

html - 提交按钮具有名称属性是否可以接受?

javascript - 尝试使用 html、javascript 创建带有 2 个 "quantity"选择器的表单

html - 在 Chrome 中运行调试器之前,CSS 无法正常工作

javascript - AdminLTE 和 AngularJS 内容包装器的最小高度错误

html - 在不移动下划线的情况下在 Y 轴上转换文本?