如何检测元素前面是否有纯文本?(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.
更多推荐
发布评论