如何检测元素前面是否有纯文本?(How do you detect if there is plain text preceding an element?)

编程入门 行业动态 更新时间:2024-10-12 05:50:58
如何检测元素前面是否有纯文本?(How do you detect if there is plain text preceding an element?)

我有一些HTML DIV元素,包含叙事风格的形式。 例如:

<div class="narrative"> My name is <input type="text"> and I am <input type="text"> years old. </div>

有没有办法用CSS检测是否在第一个<input>元素之前有纯文本,所以我可以添加左边距? 如果没有,建议如何做到这一点,而不必分类第一次输入或包裹在跨度中的纯文本?

它不会总是以纯文本开头:

<div class="narrative"> <input type="text"> is <input type="text"> years old. </div>

I have some HTML DIV elements that contain a narrative style of form. For instance:

<div class="narrative"> My name is <input type="text"> and I am <input type="text"> years old. </div>

Is there a way to detect with CSS if there is plain text before the first <input> element so I can add a left margin? If not, suggestions for ways to do this without having to class that first input or wrap the plain text in a span?

It won't always be preceded by plain text:

<div class="narrative"> <input type="text"> is <input type="text"> years old. </div>

最满意答案

CSS只能选择元素,而不能选择元素中的单个文本节点。 这是你必须通过DOM脚本和CSS做的事情。

CSS can only select elements, not individual text nodes within elements. This is something you’d have to do through DOM scripting and CSS.

更多推荐

本文发布于:2023-08-05 14:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1435152.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   文本   detect   plain   preceding

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!