Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invert CSS font-color depending on background-color

Tags:

html

css

Is there a CSS property to invert the font-color depending on the background-color like this picture?

enter image description here

like image 707
Sebastian Templin Avatar asked Jun 07 '13 10:06

Sebastian Templin


People also ask

How do I invert text and background color in CSS?

CSS allows you to invert the color of an HTML element by using the invert() CSS function that you can pass to the filter property. Because the default color of the text is black, the color is inverted into white with filter: invert(100%) syntax.

How do you change the background color of text in CSS?

Simply add the appropriate CSS selector and define the color property with the value you want. For example, say you want to change the color of all paragraphs on your site to navy. Then you'd add p {color: #000080; } to the head section of your HTML file.


1 Answers

There is a CSS property called mix-blend-mode, but it's not supported by IE. I recommend using pseudo elements. If you like to support IE6 and IE7 you can also use two DIVs instead of pseudo elements.

enter image description here

.inverted-bar {      position: relative;  }    .inverted-bar:before,  .inverted-bar:after {      padding: 10px 0;      text-indent: 10px;      position: absolute;      white-space: nowrap;      overflow: hidden;      content: attr(data-content);  }    .inverted-bar:before {      background-color: aqua;      color: red;      width: 100%;  }    .inverted-bar:after {      background-color: red;      color: aqua;      width: 20%;  }
<div class="inverted-bar" data-content="Lorem ipsum dolor sit amet"></div>
like image 133
tomatentobi Avatar answered Sep 23 '22 11:09

tomatentobi