带有元素的 CSS Content 属性
我正在做一个小项目。
我希望使用 css content 属性和 :after 伪值在另一个元素内添加锚标记 。
例如,
.classname:after { content: '<a>hello</a>'; }
// this will print "<a>hello</a>"
我需要它做的是使其具有一个工作锚标记,指向给定的href
。 我知道你可以使用类似 content: attr(title);
这样的东西,所以它将使用 .classname
title
属性作为文本,我不知道不知道这是否可能,但如果可以的话那就太酷了。
I am working on a small project.
I wish to add an anchor tag <a>
inside another element using the css content attribute and the :after pseudo.
e.g.
.classname:after { content: '<a>hello</a>'; }
// this will print "<a>hello</a>"
What I need it to do is make it have a working anchor tag, pointing to a given href
.
I know you can use something like this content: attr(title);
so it will use .classname
title
attribute as a text, I don't know if this is even possible but, it would be cool if it was.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能使用 CSS
:before
和:after
伪元素插入 HTML 元素。要添加 HTML 元素,您需要使用 JavaScript。You can't use the CSS
:before
and:after
pseudo-elements to insert HTML elements. To add HTML elements you need to use JavaScript.你不能害怕。你必须使用 javascript :(
一个简单的例子,将一个链接放入 ap 中,其 id 为 myP tho...以及一个 url 变量(实际上可以从任何值中获取)...
You cant im afraid. You have to use javascript :(
A quick example of putting a link into a p with the id of myP tho... and a variable for a url (which could be obtained from any value really)...