One of the coolest CSS3 declaration (::selection) that you can use to change the highlight colour of the selected text. You can define text and background colour of selected text.
Here is the Sample code:
1 2 3 4 5 6 7 8 |
::selection { background: #060; color: #fff; } ::-moz-selection { background: #060; color: #fff; } |
The above sample will change the selection color of paragraphs etc. If you want to change the selection color for any specific selector then you can add selector in it.
1 2 3 4 5 6 7 8 |
p.green::selection { background: #060; color: #fff; } p.green::-moz-selection { background: #060; color: #fff; } |
Demo:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Change Selection Color with CSS || Sharp-Coders.Com</title> <style type="text/css"> p.green::selection { background: #060; /* Safari */ color: #fff; } p.green::-moz-selection { background: #060; /* Firefox */ color: #fff; } </style> </head> <body> <center><h2>Change Selection Text Color</h2></center> <p class="green"> Pakistan, officially the Islamic Republic of Pakistan, is a sovereign country in South Asia. With a population exceeding 180 million people, it is the sixth most populous country in the world. The armed forces of Pakistan are the eighth largest in the world in terms of numbers in full-time service, with about 617,000 personnel on active duty and 513,000 reservists in 2010. They came into existence after independence in 1947, and the military establishment has frequently been involved in the politics of Pakistan ever since. The Chairman joint chiefs (the current chairman is General Shameem Wynne) is the highest principle officer in the armed forces, and the chief military adviser to the government though the chairman has no authority over the three branches of armed forces. The three main branches are the Army (headed by General Ashfaq Parvez Kayani), the Navy (headed by Admiral Asif Sandila), and the Air Force (headed by Air Chief Marshal Tahir Rafique Butt), and they are supported by a number of paramilitary forces. The National Command Authority is responsible for employment, for control of the development of all strategic nuclear organisations and for Pakistan's nuclear doctrine under the nuclear defence theory. Pakistan's defence forces maintain close military relations with China and the United States and import military equipment mainly from them. The defence forces of China and Pakistan carry out joint military exercises. Conscription may be introduced in times of emergency, but it has never been imposed. </p> <a href="http://sharp-coders.com" target="_blank">http://sharp-coders.com</a> </body> </html> |