Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

CSS selection style removes other styles

I'm working on a text editor with a custom spell checker. It adds a css class around misspelled words to show a red zigzag under the word.

I also use a class to style selections in the editor with a custom background color.

.spell-error {
  background-image: url("data:image/gif;base64,R0lGODlhBAADAIABAP8AAP///yH5BAEAAAEALAAAAAAEAAMAAAIFRB5mGQUAOw=="); 
  background-position: bottom; 
  background-repeat: repeat-x;
}

::selection {
  background-color: #99def7;
}
::-moz-selection {
  background-color: #99def7;
}
<p>There is a <span class="spell-error">misstake</span> in this sentence</p>
question from:https://stackoverflow.com/questions/65942842/css-selection-style-removes-other-styles

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The background-image will have a white background which overlays the background colour.
You need to have a specific background-image for the .spell-error::selection, which has the correct background colour in the actual image.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...