CSS3 ::selection behaves differently in FF & Chrome

前端 未结 2 1823
耶瑟儿~
耶瑟儿~ 2020-11-30 06:46

I\'m experimenting with the ::selection pseudo-element in CSS3. In Firefox it works and looks great. My site has a dark navy blue background.

I set the

2条回答
  •  感动是毒
    2020-11-30 07:05

    As Steven Lu has pointed out in a comment to tw16's answer, the opacity treshold is 255/256.

                     calc

    In other words, 0.996 will work but 0.997 will not.

    Let's see it in action:

    ::selection
    {
      background: rgba(255, 127, 0, 0.996);
      color: white;
    }
    
    ::-moz-selection
    {
      background: #F80;
      color: white;
    }

    The domestic cat is a small, usually furry, domesticated, and carnivorous mammal. They are often called a housecat when kept as an indoor pet, or simply a cat when there is no need to distinguish them from other felids and felines. Cats are often valued by humans for companionship.

    A Melvin, Michigan woman was brutally attacked by a stray cat and shocking footage of the mauling has already gained a million views on YouTube.

    The woman, who identified herself to reporters only as Maxx, endured the horrific attack November 30 but only recently realized it had been caught on her home surveillance camera.

    The attack left her face swollen and infected and the cat named Buddy dead as officials were forced to test it for rabies.

    As you may see in Chrome, this obscures the images. To fix that, we need to apply specific styles to image selection, with a lower opacity:

    ::selection
    {
      background: rgba(255, 127, 0, 0.996);
      color: white;
    }
    
    ::-moz-selection
    {
      background: #F80;
      color: white;
    }
    
    img::selection
    {
      background: rgba(255, 127, 0, 0.8);
      color: white;
    }

    The domestic cat is a small, usually furry, domesticated, and carnivorous mammal. They are often called a housecat when kept as an indoor pet, or simply a cat when there is no need to distinguish them from other felids and felines. Cats are often valued by humans for companionship.

    A Melvin, Michigan woman was brutally attacked by a stray cat and shocking footage of the mauling has already gained a million views on YouTube.

    The woman, who identified herself to reporters only as Maxx, endured the horrific attack November 30 but only recently realized it had been caught on her home surveillance camera.

    The attack left her face swollen and infected and the cat named Buddy dead as officials were forced to test it for rabies.

    In Firefox, there is no way to override the blue selection color on images, it seems.

提交回复
热议问题