Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    1,063
    Thanks
    12
    Thanked 241 Times in 240 Posts

    Clickable Area for Div

    Hello,

    I have a div acting as a large clickable area (button) using cursor: pointer;. However, since there is text within it, when a user clicks the button and drags his mouse, he can accidently highlight everything and his cursor changes to text.

    Code:
    user-select: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -o-user-select: none;
    This stops the user from selecting, however the user's cursor still changes to text. how can I prevent this without using <button> or <a> (which changes the cursor to default)
    Last edited by Sammy12; 11-06-2011 at 10:23 PM.

  • #2
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmmmm. sorry bro. i do'nt have solution

  • #3
    Registered User
    Join Date
    Jun 2011
    Posts
    1,063
    Thanks
    12
    Thanked 241 Times in 240 Posts
    lol thanks for at least replying + bumping the thread

    hopefully one of the big dogs will help me with this. I'm sure this problem has happened before.

  • #4
    New Coder
    Join Date
    Nov 2011
    Location
    Seattle, WA & Big Island, HI
    Posts
    13
    Thanks
    0
    Thanked 3 Times in 3 Posts
    use CSS cursor [pointer]

  • #5
    Registered User
    Join Date
    Jun 2011
    Posts
    1,063
    Thanks
    12
    Thanked 241 Times in 240 Posts
    Quote Originally Posted by hawaiiwebdesign View Post
    use CSS cursor [pointer]
    ...no that does not work. It's implied that I already used cursor: pointer;. When a user clicks down on the button and holds for 2 sec, the cursor changes to text.

  • #6
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,667
    Thanks
    22
    Thanked 1,826 Times in 1,810 Posts
    Hello Sammy12,
    I'm not sure why you don't want to use an anchor, there are still a lot of browsers in use that need to use anchor to be clickable.

    What does this do for you -
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {
    	margin: 0;
    	background: #FC6;
    	cursor: pointer;
    }
    #container {
    	width: 800px;
    	margin: 30px auto;
    	padding: 20px 0 300px 20px;
    	background: #999;
    	overflow: auto;
    }
    a {
    	height: 50px;
    	width: 100px;
    	display: block;
    	line-height: 50px;
    	text-align: center;
    	text-decoration: none;
    	color: #000;
    	background: #f00;
    }
    </style>
    </head>
    <body>
        <div id="container">
        	<a href="">some text</a>
        <!--end container--></div>
    </body>
    </html>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #7
    Registered User
    Join Date
    Jun 2011
    Posts
    1,063
    Thanks
    12
    Thanked 241 Times in 240 Posts
    change the <a> to a <div>
    then click and hold on the div or click and drag

    there's where my problem is a) the area is selectable (solved that) b) the cursor changes to text

  • #8
    Master Coder Excavator's Avatar
    Join Date
    Dec 2006
    Location
    Alaska
    Posts
    9,667
    Thanks
    22
    Thanked 1,826 Times in 1,810 Posts
    Look at this in FF and see if that's what you're looking for. Still not right in IE...
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <style type="text/css">
    html, body {
    	margin: 0;
    	background: #FC6;
    }
    #container {
    	width: 800px;
    	margin: 30px auto;
    	padding: 20px 0 300px 20px;
    	background: #999;
    	overflow: auto;
    }
    #linked {
    	height: 50px;
    	width: 100px;
    	display: block;
    	line-height: 50px;
    	text-align: center;
    	text-decoration: none;
    	cursor: pointer;
    	color: #000;
    	background: #f00;
    }
    #linked span {
    	user-select: none;
    	-webkit-user-select: none;
    	-khtml-user-select: none;
    	-moz-user-select: none;
    	-o-user-select: none;
    	cursor: pointer;
    }
    </style>
    </head>
    <body>
        <div id="container">
        	<div id="linked"><span>some text</span></div>
        <!--end container--></div>
    </body>
    </html>
    Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
    Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad

  • #9
    Registered User
    Join Date
    Jun 2011
    Posts
    1,063
    Thanks
    12
    Thanked 241 Times in 240 Posts
    YES, i tested in chrome and ff

    that's funny, let me check why my website doesn't do that




    EDIT: wait no, could you get it for a <div> :P I would have just used a <button> if I wanted to use an inline element
    Last edited by Sammy12; 11-06-2011 at 11:12 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •