Answer to disabling text selection using CSS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rbuczynski
    New Member
    • Mar 2010
    • 10

    Answer to disabling text selection using CSS

    I've read two threads that have been closed in which a user posed the question,

    "Can I disable text selection using CSS?"

    The responses were either hopeless or critical of the inquirer. I thought it'd be a nice gesture to answer the question with what was expected as well as some pointers regarding the topic.

    Answer: YES.
    An article posted some time ago describes the process of overriding the default selection color employed by browsers. This property is accessible through CSS.

    Code:
    Code:
    ::selection {
    	background: none; /* Safari */
    	}
    ::-moz-selection {
    	background: none; /* Firefox */
    }
    The article where I found this can be read here:
    One of those cool CSS3 declarations that you can use today is ::selection, which overrides your browser-level or system-level text highlight color with a


    Although the article describes changing the color of the selection box, we can simulate a disabled selection by changing the background property to "none".

    PROS: Your desired result is achieved.
    CONS: Limited support across all browsers; not a truly disabled selection.

    I'll add that the referenced site, css-tricks.com, is an excellent source for these types of questions. Additionally, visit smashingmagazin e.com for articles that cover the latest web technologies and tricks being used by developers.

    Hope this helps!
  • rbuczynski
    New Member
    • Mar 2010
    • 10

    #2
    *note to admin*
    I've posted this thread in the JavaScript forum because this is where the original questions appeared.

    Please move thread to HTML/CSS if necessary!

    Comment

    Working...