Results 1 to 9 of 9

Thread: :focus on divs not working??

  1. #1
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default :focus on divs not working??

    Hello everyone,
    Can anyone please tell me what I am doing wrong in the following??

    Code:
    #test {
    height: 100px;
    width: 100px;
    background-color: red;
    border: 1px solid;
    }
    #test:focus {
    border: 1px dotted;
    }
    markup

    Code:
    ...(rest of the code)
    <div id="test"></div>
    ...
    What I want to do is when the user click on the div it should turn it's border into dotted but unfortunately it is not going as it should. Any ideas?? Thanks.

  2. #2
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    well you need a border color. Also what browser are you testing in?

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by shachi
    Can anyone please tell me what I am doing wrong in the following??
    I can tell you from the thread title: div elements don't receive focus. Focus is typically limited to only links and form controls.

    I say typically because there are some exceptions. For example, Opera provided rich keyboard navigation features, allowing the user to move between headings and even elements. In this mode, moving to a non-interactive element could give it focus (it appears to take a couple of seconds; I suppose Opera wants to be sure that the focus was intended). Browsers that are aimed at assisting disabled users might also offer similar features.

    What I want to do is when the user click on the div it should turn it's border into dotted but unfortunately it is not going as it should. Any ideas??
    Scripting, and all its attached caveats, is your only option for a wider audience.

    Mike

  4. #4
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    blm126: firefox, no I don't think it is a must to declare border color if nothing is declared then it sets the default value #000000.
    mwinter: so shall I use javascript for this?? something like

    Code:
    ...
    function focus(obj){
    obj.style.border = "1px dotted";
    }
    ...
    <div id="test" onclick="focus(this)"></div>
    ...
    Last edited by shachi; 08-17-2006 at 12:56 PM.

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by shachi
    function focus(obj){
    obj.style.border = "1px dotted";
    }
    Better would be:

    Code:
    /* Use names that reflect purpose... */
    function setBorder(element) {
        /* ...and feature detect! */
        if (element.style) {
            element.style.border = '1px dotted';
        }
    }
    but yes, something like that.

    Mike

  6. #6
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok thanks!!!

  7. #7
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by shachi
    blm126: firefox, no I don't think it is a must to declare border color if nothing is declared then it sets the default value #000000.
    No, it sets it to the browsers default. That is an important difference

  8. #8
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by blm126
    [Default border colours] No, it sets it to the browsers default.
    No, it doesn't. If the colour isn't specified, the same colour as the color property is used. See section 8.5.2 in the CSS 2 Specification, particularly the example at the end.

    That is an important difference
    Quite.

    Mike

  9. #9
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    My bad , but in my defense if you apply the transitive property...

Bookmarks

Posting Permissions

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