1

I am new to HTML/CSS and I faced with two troubles with elements selection.

I write a html page, which contains a centered div and elements inside it.

I have two troubles:

  1. How to bound selection area by div borders?
  2. Some elements use "old" selection color, how to change it?

I placed two images below for better understanding what I mean:

without selection: without selection

with selection: with selection


I tried to change selection background color by following peace of css code:

*::selection {
color: #330066;
background:yellow;
}

*::-moz-selection {
color: #330066;
background:yellow;
}

[EDIT]: You can see a similar code here: http://jsfiddle.net/phvoronov/7ZQ5z/1/.

Filipp Voronov
  • 4,077
  • 5
  • 25
  • 32
  • Can you set up a jsfiddle? It is also not clear what goes wrong? How bound selection area by div borders? It is only on text not the padding or borders. http://jsfiddle.net/g943Z/3/. The universal * selector will aplly this on all elements in the document. – JohanVdR Mar 23 '14 at 19:17
  • @JohanVandenRym, i added a link to jsfiddle (see EDIT to my post). – Filipp Voronov Mar 23 '14 at 19:30
  • @JohanVandenRym, "How bound selection area by div borders?" When I select elements inside my main div, selection area must be only inside my div, not through the entire width of the page. – Filipp Voronov Mar 23 '14 at 19:37
  • You specify on what div you want to apply it div::selection {} – JohanVdR Mar 23 '14 at 19:52
  • @JohanVandenRym I want it on my main div (id="main-div"). If you mean that i should add #main-div::selection{}, it doesn't help (see http://jsfiddle.net/phvoronov/7ZQ5z/2/) or I did it wrong. – Filipp Voronov Mar 23 '14 at 20:09

0 Answers0