Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > HTML > HTML Code Clinic
|
HTML Code Clinic Do you have some HTML code you'd like to share and get suggestions from others for tweaking or improving it? This discussion is the place.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the HTML Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2004, 04:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default Adding style to text selected by user

Hi guys,
I have a page with light-blue text (#9697F3) on white background. If I click and drag to select some text, the background remains white but the color of the text turns a darker blue.

If I change the color to a darker blue (#123456) and select the text again, it inverts the bg/fg - ie. displays white characters on dark-blue bg.

How can I control the behaviour of selected text, using CSS (or other)?

Ps. Actually the background isn't white, it's 'browser-default' - bad Jonax - I know... ;)
 
Old June 9th, 2004, 02:07 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

CSS 3 has introduced a new pseudo-element called ::selection, but as far as I've read it only works on Apple's Safari browser (so far).

::selection {
    /* Style declarations for selected text */
}

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old June 9th, 2004, 02:33 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Maybe you could do something with JavaScript like this:

function highlightSelected()
{
 if(document.selection.type = "text")
 {
  //formatting stuff
 }
}
document.onmouseup = highlightSelected;

HTH,

Snib

<><
 
Old June 9th, 2004, 03:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

Thanks Rich & Snib,
I'll have a go at it in the morning...

I look forward to be including the string 'Best viewed with Safari' on the front page ;)






Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.net adding data in a selected node saikoboarder XML 9 May 16th, 2008 06:37 AM
adding style via CSS to XML documents crmpicco XML 3 December 1st, 2006 11:50 AM
How to retrieve last selected text line in text bo garetho General .NET 1 May 3rd, 2005 09:17 PM
is the text in text box selected? nerssi Javascript 4 September 21st, 2004 09:26 AM
Dynamically adding style sheets ? Xnera ASP.NET 1.0 and 1.1 Basics 1 August 21st, 2003 06:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.