[英]Change Border Color of Div Based on Selection With CSS and JavaScript
[英]Is there a way to change text color at border of div with css? Maybe tricky !
我有一个带有文本的嵌套 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>
我的问题:有没有办法用 css 更改从父 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>
尝试用span
标签包装它并以这种方式设置样式。
<div style="position:absolute;width:300px;background:yellow;color:red">
this text will overflow into the parent div!
<div style="position:absolute;top:0;height:20px;width:150px;left:0;
background:red;overflow:hidden;white-space:nowrap;color:yellow">
this text will overflow into the parent div!
</div>
</div>
:)
我不相信这是可能的,因为文本是内部 div 的孩子,内部 div 的颜色将优先。
一种解决方案是将文本拆分为两个元素并手动为每个元素着色,尽管我承认这不是一个好的解决方案。
我能想到的唯一方法是将一个部分透明的div
放在不属于孩子的父母部分上。 然而,这也会与父background-color
混淆,并且不允许您 select 透明div
下方的文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.