Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: SPAN width in FF

  1. #1
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default SPAN width in FF

    Hi,

    I'm having some trouble with this script (I'm pretty sure it has to deal with the SPAN's width.)

    Code:
    <html>
    <head>
    <style type="text/css">
    .tablespan {
    border:1px solid black;
    padding:2px;
    width:120px
    }
    .tablespan:hover {
    background:highlight;
    color:white
    }
    </style>
    </head>
    <body>
    <div id="spantable"></div>
    </body>
    </html>
    The width won't be 120px, it'll be the width of the text (in FireFox)?? Any help appreciated.
    - Mike

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    <span>s are inline elements. You can only set width on block-level elements. You can try display:block, but depending on your layout it might mess things up.

    Also, that :hover won't work in IE.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Also, that :hover won't work in IE.
    Yeah, I rigged up this script for IE

    Code:
    var ie = document.all
    var ns = document.getElementById && !ie
    document.onmouseover=function(e) {
    var obj = ns ? e.target : event.srcElement
    if (obj.className=="tablespan") {
    obj.style.background="highlight"
    obj.style.color="white"
    obj.onmouseout=function() {
    obj.style.background="white"
    obj.style.color="black"
    }
    }
    }
    - Mike

  4. #4
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Alright this is actually what I'm doing: (creating tables with div elements)

    Code:
    <html>
    <head>
    <script type="text/javascript">
    onload=function() {
    var rows=new Array
    rows[0]=["Header Col 1","Col 1 Row 1","Col 1 Row 2"]
    rows[1]=["Header Col 2","Col 2 Row 1","Col 2 Row 2"]
    rows[2]=["Header Col 3","Col 3 Row 1","Col 3 Row 2"]
    
    for (i=1;i<=rows.length-1;i++) {
    var table=document.createElement("SPAN")
    var code
    code+="<span class='tablespan'>"+rows[0][i]+"</span>"+
    "<span class='tablespan'>"+rows[1][i]+"</span>"+
    "<span class='tablespan'>"+rows[2][i]+"</span><br>"
    spantable.appendChild(table)
    }
    table.innerHTML="<span class='tablespan'>"+rows[0][0]+"</span>"+
    "<span class='tablespan'>"+rows[1][0]+"</span>"+
    "<span class='tablespan'>"+rows[2][0]+"</span>"+"<br>"+code.substring(9,code.length)
    }
    var ie = document.all
    var ns = document.getElementById && !ie
    document.onmouseover=function(e) {
    var obj = ns ? e.target : event.srcElement
    if (obj.className=="tablespan") {
    obj.style.background="highlight"
    obj.style.color="white"
    obj.onmouseout=function() {
    obj.style.background="white"
    obj.style.color="black"
    }
    }
    }
    </script>
    <style type="text/css">
    .tablespan {
    border:1px solid black;
    padding:2px;
    width:120px;
    display:block
    }
    .tablespan:hover {
    background:highlight;
    color:white
    }
    </style>
    </head>
    <body>
    <div id="spantable"></div>
    </body>
    </html>
    Using display:block has the same effect as div which I don't want, I want all of the element to be on the same line.

    Remove the display:block, and see what happens in IE, then in firefox.

    Help please
    - Mike

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I want all of the element to be on the same line.
    You need to use two or three floated divs, then.
    Code:
    var ie = document.all
    var ns = document.getElementById && !ie
    Browser detection is A Bad Thing.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Browser detection is A Bad Thing.
    It may be, but it works. If the browser is IE the script works, and if it is FireFox or other hoverseudo class supporting browsers it works too.
    - Mike

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    But you only use it once, and you might as well replace that line with:
    Code:
    var obj = (e && e.target ? e.target : (window.event && window.event.srcElement ? window.event.srcElement));
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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

    Default

    Quote Originally Posted by mburt
    Alright this is actually what I'm doing: (creating tables with div elements)
    That's just daft. Stop it. If you have tabular data, use a table. If you don't, use appropriate semantic markup.

    Quote Originally Posted by Twey
    Browser detection is A Bad Thing.
    It may be, but it works.
    For a limited value of "works". For a start, your "test" for MSIE will match many more browsers than just IE, likewise for Netscape.

    The point that is important regarding browser detection is that it doesn't tell you (the author) what you actually want to know. The question is, "Will the host support X?" Feature detection will answer that well. Unless you know the features of every single browser, past, present and future (and nobody never will), browser detection is nothing more than a maintenance burden.


    Quote Originally Posted by Twey
    var obj = (e && e.target ? e.target : (window.event && window.event.srcElement ? window.event.srcElement));
    I would go with the following construct, personally:

    Code:
    var global = this;
    
    function listener(event) {
        if (event || (event = global.event)) {
            var target = event.target || event.srcElement;
    
            if (target /* && <feature detection, if necessary> */) {
                /* ... */
            }
        }
    }
    Fewer property lookups, if nothing else.

    Mike

  9. #9
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    That's just daft. Stop it. If you have tabular data, use a table. If you don't, use appropriate semantic markup.
    Why the hell would you want to know why I'm trying to do this? I was trying to do it, first of all. I was testing out I method I thought of. Your advice was nothing that was already said, and superfluous.

    Remember, I was the one questioning, not correcting.
    - Mike

  10. #10
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    What is the advantage of doing:
    Code:
    var global = this;
    ... when window is accessible globally?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •