Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we change the color of the overflown text?

Tags:

css

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>

enter image description here

like image 291
Nean Der Thal Avatar asked Jun 09 '21 11:06

Nean Der Thal


People also ask

Is it possible to change the color of the overflow icon?

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).

How can I change the color of text in a 16P font?

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:

How to change the color of the text in HTML?

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.

Why are the dots in the text div not inheriting the color?

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.


2 Answers

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.

like image 98
CBroe Avatar answered Oct 13 '22 05:10

CBroe


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>
like image 42
Temani Afif Avatar answered Oct 13 '22 06:10

Temani Afif