最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - change text color depending on background imagecolor - Stack Overflow

programmeradmin1浏览0评论

on this page i have the first div as a dark image and the second as a light background.

i want the sidebar text color to be light on the dark image and dark on the light.

how would i set the color according to what div is in the background? just need it for two color options.

this is another example of what I'm looking for / example html:

 <div id="home_wrapper">
    <div id="home_top_t_wrap"> <!-- DARK BACKGROUND -->
        <h1 class="top_text_h1"> Shop New York Like Never Before </h1> <!-- TEXT THAT NEEDS TO GO FROM LIGHT TO DARK -->    </div>
    <div id="the_market_container"> <!-- LIGHT BACKGROUND --></div>
 </div>

on this page i have the first div as a dark image and the second as a light background.

i want the sidebar text color to be light on the dark image and dark on the light.

how would i set the color according to what div is in the background? just need it for two color options.

this is another example of what I'm looking for http://www.acnestudios.com/ example html:

 <div id="home_wrapper">
    <div id="home_top_t_wrap"> <!-- DARK BACKGROUND -->
        <h1 class="top_text_h1"> Shop New York Like Never Before </h1> <!-- TEXT THAT NEEDS TO GO FROM LIGHT TO DARK -->    </div>
    <div id="the_market_container"> <!-- LIGHT BACKGROUND --></div>
 </div>
Share Improve this question edited Oct 8, 2015 at 13:24 Michael Benjamin 371k110 gold badges613 silver badges730 bronze badges asked Oct 3, 2015 at 23:28 rs19rs19 6671 gold badge10 silver badges23 bronze badges 2
  • 2 To answer this question, you realistically need to show enough of your HTML and CSS to allow us to recreate your problem. A link to your page is not sufficient, because as soon as your problem is solved that page will be changed rendering the question useless or nonsensical to future visitors to the site. – David Thomas Commented Oct 4, 2015 at 4:52
  • Possible duplicate of Change text color based on brightness of the covered background area? – KyleMit Commented May 1, 2017 at 14:05
Add a comment  | 

3 Answers 3

Reset to default 5

I like use this plugin http://aerolab.github.io/midnight.js/ you can try it

One way to adjust the color of text based on the color of the background is with background-check.

From the github page:

Automatically switch to a darker or a lighter version of an element depending on the brightness of images behind it.

Here are a few other options:

  • Is it possible to change text color based on background color using css?
  • Change text color based on brightness of the covered background area?
  • Dynamically adjust text color based on background image
  • Invert CSS font-color depending on background-color

UPDATE

Check out the sidebar on this website: http://provisions.convoy.nyc/

A clean, smooth color transition for the text based on the background image or color.

I spoke with the designer. They use: http://aerolab.github.io/midnight.js

<div id="home_wrapper">
    <div id="home_top_t_wrap"> <!-- DARK BACKGROUND -->
        <h1 class="top_text_h1"> Shop New York Like Never Before </h1> <!-- TEXT THAT NEEDS TO GO FROM LIGHT TO DARK -->    </div>
    <div id="the_market_container"> <!-- LIGHT BACKGROUND --></div>
 </div>


    <script>

    $(document).ready(function() {
        $("#home_top_t_wrap").hover(function() {
            $("body").css("background-color","light"); //change light to your color
        });
    $("#the_market_container").hover(function() {
            $("body").css("background-color","dark"); //change dark to your color
        });

    });
    </script>

I tried on div hover. Hope this helps

发布评论

评论列表(0)

  1. 暂无评论