How to change the selected text color In Internet explorer?

前端 未结 5 853
无人及你
无人及你 2020-12-21 00:29

I have seen in many weblogs when we select text the background color of the text changes rather than usual blue. This Tech Works in Firefox and Safari, is there any method a

相关标签:
5条回答
  • 2020-12-21 00:49

    Not supported on IE as far as I know. Unless there's some clever hack I don't know about.

    0 讨论(0)
  • 2020-12-21 00:52

    This?

    <style>
    ::selection {color:red;background:yellow;}
    ::-moz-selection {color:red;background:yellow;}
    </style>
    

    http://www.w3schools.com/cssref/tryit.asp?filename=trycss3_selection

    0 讨论(0)
  • I think it would be difficult to emulate

    • You could try and set a background colour for the text selected, but the default blue highlighting will probably ruin your effect
    • The browser would probably choke on some systems when someone is selecting a lot of text and changing their selection rapidly.

    I think you should use CSS for the browsers that support it, and wait patiently for IE to adopt this.

    0 讨论(0)
  • 2020-12-21 01:03

    You could always remove it.

    
    
        
    
            if (window.getSelection) {
              if (window.getSelection().empty) {  // Chrome
                window.getSelection().empty();
              } else if (window.getSelection().removeAllRanges) {  // Firefox
                window.getSelection().removeAllRanges();
              }
            } else if (document.selection) {  // IE?
              document.selection.empty();
            }
    
        
    
    
    
    0 讨论(0)
  • 2020-12-21 01:07

    It can't be done in IE with pure CSS and I don't know of any pre-packaged JS that will get the job done, either.

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