Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of text responding to background color

Tags:

html

css

Consider this example: codepen

.infobox {
  width: 110mm;
  height: 65mm;
  background-image: url(https://i.pinimg.com/564x/86/70/f2/8670f2ab34bf4082bf3cef004aae0826.jpg);
  background-size: cover;
  position: relative;
}

.text {
  position: absolute;
  bottom: 0;
  text-align: center;
  color: white;
}
<div class="infobox">
  <span class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel quam in enim pulvinar fringilla. Etiam molestie convallis pharetra. Sed et tortor tortor. Vestibulum ligula ex, rhoncus semper metus ut, hendrerit porttitor risus. Quisque at porta magna. Phasellus vel vulputate diam. Maecenas sem est, aliquet nec odio euismod, posuere luctus nisl. Vestibulum posuere iaculis massa, sed cursus dui pellentesque sed.</span>
</div>

I generate many of images and sometimes light text is ok, but in this case it is not.

What i tried was:

  1. mix-blend-mode - did not help

  2. Sth like: filter: invert(1) grayscale(1) contrast(16) drop-shadow(.05em .05em orange);

Remember that it should work in many cases not only this one e.g. dark/light background. Can i manipulate color of text dynamicly?

like image 641
tryingHard Avatar asked Oct 13 '18 21:10

tryingHard


People also ask

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

Changing Text Background Color in CSS. To change the background color of inline text, go to the <head> section of your web page. Simply add the appropriate CSS selector and define the color and background-color property with the values you want. Say you want to change the background color of links to yellow.

Is it possible to change the color of the text?

Yes it is possible. Select the text you want "shaded" and then choose Format > Borders and Shading > Shading (tab). Make sure the "Apply To" list box says "Text" and then select your shading color and click Ok. Provides free AuthorTec add-ins for Mac & Win-Office.

How do I change the color and appearance of my screen?

This opens up the following Color and Appearance window (click to enlarge): As you can see Color and Appearance window allows you to choose colors of windows background, text, hyperlinked text, disabled text; and both foregrounds and backgrounds of selected text, active window titles, inactive window titles and buttons.

Why is the background color of selected text black in word?

As you have checked the high contrast settings, it is set to off and the issue appears only in Word application, rest other Office applications are fine, please try the following suggestions and check if there’s any change. Open Word application in safe mode and then try selecting the text, check if background color of selected text is still black.


2 Answers

You may simply add a text-shadow with a dark color and you will have a better rendring whataver the image you will use:

.infobox {
    width: 110mm;
    height: 65mm;
    background:
    linear-gradient(to bottom,transparent,#fff),
    url(https://i.pinimg.com/564x/86/70/f2/8670f2ab34bf4082bf3cef004aae0826.jpg);
  background-size: cover;
  position: relative;
}

.text {
  position: absolute; bottom: 0; 
  text-align: center; color: white;
  text-shadow: -1px 0 1px #000,
               1px 0 1px #000,
               1px 1px 1px #000,
               -1px -1px 1px #000,
               0 1px 1px #000,
               0 -1px 1px #000;
}
<div class="infobox">
  <span class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel quam in enim pulvinar fringilla. Etiam molestie convallis pharetra. Sed et tortor tortor. Vestibulum ligula ex, rhoncus semper metus ut, hendrerit porttitor risus. Quisque at porta magna. Phasellus vel vulputate diam. Maecenas sem est, aliquet nec odio euismod, posuere luctus nisl. Vestibulum posuere iaculis massa, sed cursus dui pellentesque sed.</span>
</div>
like image 135
Temani Afif Avatar answered Nov 16 '22 01:11

Temani Afif


Another solution could be to make your image darker.

.infobox {
  width: 110mm;
  height: 65mm;
  background-image:url(https://i.pinimg.com/564x/86/70/f2/8670f2ab34bf4082bf3cef004aae0826.jpg);
  background-size: cover;
  position: relative;
}

.infobox:before {
  content: '';
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(0, 0, 0, 0.4);
}

.text {
  position: absolute; bottom: 0; 
  text-align: center; color: white;
}
<div class="infobox">
  <span class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi vel quam in enim pulvinar fringilla. Etiam molestie convallis pharetra. Sed et tortor tortor. Vestibulum ligula ex, rhoncus semper metus ut, hendrerit porttitor risus. Quisque at porta magna. Phasellus vel vulputate diam. Maecenas sem est, aliquet nec odio euismod, posuere luctus nisl. Vestibulum posuere iaculis massa, sed cursus dui pellentesque sed.</span>
</div>
like image 30
Quentin Veron Avatar answered Nov 16 '22 02:11

Quentin Veron