How can I invert color using CSS?

前端 未结 3 1798
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 01:37

HTML

inverted color

CSS

div {
    background-color: #f00;
}
p { 
    color:         


        
相关标签:
3条回答
  • 2020-12-05 02:05

    Here is a different approach using mix-blend-mode: difference, that will actually invert whatever the background is, not just a single colour:

    div {
      background-image: linear-gradient(to right, red, yellow, green, cyan, blue, violet);
    }
    p {
      color: white;
      mix-blend-mode: difference;
    }
    <div>
      <p>Lorem ipsum dolor sit amet, consectetur adipiscit elit, sed do</p>
    </div>

    0 讨论(0)
  • 2020-12-05 02:24

    Add the same color of the background to the paragraph and then invert with CSS:

    div {
        background-color: #f00;
    }
    
    p { 
        color: #f00;
        -webkit-filter: invert(100%);
        filter: invert(100%);
    }
    <div>
        <p>inverted color</p>
    </div>

    0 讨论(0)
  • 2020-12-05 02:26

    I think the only way to handle this is to use JavaScript

    Try this Invert text color of a specific element

    If you do this with css3 it's only compatible with the newest browser versions.

    0 讨论(0)
提交回复
热议问题