Javascript 有没有一种方法可以使用css更改div边界处的文本颜色?也许很棘手!

Javascript 有没有一种方法可以使用css更改div边界处的文本颜色?也许很棘手!,javascript,jquery,css,Javascript,Jquery,Css,我有一个带文本的嵌套div。文本按设计从子div溢出到父div <div style="position:absolute;width:300px;background:yellow"> <div style="position:relative;height:20px;width:150px;left:0; background:red;overflow:visible;white-space:now

我有一个带文本的嵌套div。文本按设计从子div溢出到父div

<div style="position:absolute;width:300px;background:yellow">
     <div style="position:relative;height:20px;width:150px;left:0;
                                 background:red;overflow:visible;white-space:nowrap">
        this text will overflow into the parent div!
     </div>
</div>

此文本将溢出到父div中!

我的问题:有没有一种方法可以用css更改父div中从子级边界开始的文本颜色?现在,颜色与溢出到父div的文本相同。

尝试用
span
标记将其包装并设置样式。

尝试用
span
标记将其包装并设置样式。

我认为这是不可能的,因为文本是内部div的子级,内部div的颜色将优先


一个解决方案是将文本分成两个元素,并手动为每个元素着色,尽管我承认这不是一个好的解决方案。

我认为这是不可能的,因为文本是内部div的子元素,所以内部div的颜色将优先


一个解决方案是将文本分成两个元素,并手动为每个元素着色,尽管我承认这不是一个好的解决方案。

有点欺骗,但这会起作用:

<div style="position:absolute;width:300px;background:yellow">
    <div style="position: absolute; top: 0; color: pink;">
        this text will overflow into the parent div!
    </div> 
    <div style="position:relative;height:20px;width:150px;left:0;
                             background:red;overflow:hidden;white-space:nowrap">
        this text will overflow into the parent div!
    </div>

</div>

此文本将溢出到父div中!
此文本将溢出到父div中!

证据:

是一种欺骗,但这会起作用:

<div style="position:absolute;width:300px;background:yellow">
    <div style="position: absolute; top: 0; color: pink;">
        this text will overflow into the parent div!
    </div> 
    <div style="position:relative;height:20px;width:150px;left:0;
                             background:red;overflow:hidden;white-space:nowrap">
        this text will overflow into the parent div!
    </div>

</div>

此文本将溢出到父div中!
此文本将溢出到父div中!

证明:

我能想到的实现这一点的唯一方法是在父对象的非子对象部分放置一个部分透明的
div
。但是,这也会影响父对象的
背景色
,不允许您选择透明
div
下面的文本。我能想到的唯一方法是在父对象的非子对象部分放置一个部分透明的
div
。但是,这也会影响父对象的
背景色
,并且不允许您选择透明
div


此文本将溢出到父div中!
此文本将溢出到父div中!
:)


此文本将溢出到父div中!
此文本将溢出到父div中!
:)