If I have a div
with overflow: visible;
, can I make the color of the overflow text different than the color of the text inside the div
?
Something like this (the black box is the div):
<div style="overflow: visible; max-width: 200px;">
Text will for sure overflow
</div>
It seems normal to provide a whole new overflow icon for your app, replacing the standard one, just to get the right color. Android’s new Toolbar, which replaces ActionBar (with some awkward code), makes it easier to change the title text color and the color of the menu overflow icon (and the Up/Back icon).
It's the same as 64 pixels, because 16px makes 1rem unless you change the root font-size ( html) to another value. To change the color of the text, you can use the style attribute, and then set a value with the color property: Combining the font-size and color properties gives us this in the browser:
To change the color of the text, you can use the style attribute, and then set a value with the color property: Combining the font-size and color properties gives us this in the browser: You can also change the color and size of text in an external stylesheet. Most importantly, you have to link the external CSS in the head section of your HTML.
Parts of the text are in a span for coloring. The text div has all necessary styles for text-overflow with dots at the end (ellipsis), but the dots are not inheriting the span 's color, because their definition is on the div. When I put the definition on the span, it ignores its parent's width.
Maybe with a pseudo element placed over the actual div dimensions, and using mix-blend-mode
to get it to turn red color applied to the whole text, dark again:
div {
position: relative;
overflow: visible;
max-width: 100px;
white-space: nowrap;
border: 1px solid black;
color: #f00;
}
div::after {
content: "";
position: absolute;
top:0; left:0; right:0; bottom:0;
background: #fff;
mix-blend-mode: color;
}
<div>Text will for sure overflow</div>
Not sure whether that might collide with any additional requirements for whole page backgrounds or something though, you’d have to test it in whatever specific scenario you need it in.
Instead of mix-blend-mode
, applying some sort of filter
might give similar results.
backdrop-filter
can also do it
.box {
position: relative;
max-width: 100px;
white-space: nowrap;
padding: 3px;
border: 1px solid black;
color: #f00;
}
.box::after {
content: "";
position: absolute;
inset: 0;
backdrop-filter: grayscale(1);
}
<div class="box">Text will for sure overflow</div>
Or use background coloration like below:
.box {
--d:100px;
position: relative;
max-width: var(--d);
white-space: nowrap;
padding: 3px;
border: 1px solid black;
}
.box span {
background:linear-gradient(90deg,#000 calc(var(--d) + 3px),red 0); /* we need to account for the padding */
color:transparent;
-webkit-background-clip:text;
background-clip:text;
}
<div class="box"><span>Text will for sure overflow</span></div>
<div class="box" style="--d:80px"><span>Text will for sure overflow</span></div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With