Is Firefox or IE to blame

Last post 03-24-2008 9:13 PM by stevendshields. 18 replies.

Sort Posts:

  • Is Firefox or IE to blame

    12-12-2006, 6:49 AM
    • Loading...
    • avida
    • Joined on 09-17-2005, 3:07 PM
    • Posts 38

    Hi all,

     This is an old one and I've never found a good answer yet. So

    <ASP:Label ID="label1" runat="server" Text="This is label 1" WIDTH="250px" /> textbox control <br/>

    <ASP:Label ID="label2" runat="server" Text="This is another label" WIDTH="250px" /> textbox control <br/>

    In IE 6 and 7 it renders correctly and the textbox controls line up great. In Firefox 1.x or 2.x it doesn't work.

    So is the WIDTH property of the label control an IE only feature or is there a simple solution for cross browser compatability ?

     Many Thanks.

  • Problems with label:Width in Firefox

    12-13-2006, 12:40 PM
    • Loading...
    • Dejan Vesic
    • Joined on 12-04-2006, 10:08 PM
    • Belgrade, Serbia
    • Posts 461

    If you need someone to blame, blame IE Smile

    Let me explain: Label gets rendered in <span> element; by W3C standard, <span> element is of type inline, so it does not have width (it is not applicable to it).

    So, Firefox and other browsers render label correctly. If you do want that kind of behaviour, you can do following:

    Create CSS class which will be applied on labels which needs width:

    .fixedLabel 
    {
        display: block;
        float: left;
    }

     Now, give to your labels this CssStyle:

    <asp:Label ID="label1"  CssClass="fixedLabel" runat="server" Text="This is label 1" width="250px" /><asp:TextBox
        ID="TextBox1" runat="server"></asp:TextBox><br/>
    <asp:Label ID="label2" CssClass="fixedLabel" runat="server" Text="This is another label" WIDTH="250px" /><asp:TextBox
        ID="TextBox2" runat="server"></asp:TextBox><br/>
    

     

    and display should be ok in all compliant browsers.

    Regards,
    Dejan Vesić

    MCAD for .Net technologies | http://www.vesic.org/english/ | Blog: http://www.vesic.org/english/blog/
    Filed under: , ,
  • Re: Problems with label:Width in Firefox

    12-13-2006, 12:45 PM
    • Loading...
    • RTernier
    • Joined on 06-05-2003, 1:40 AM
    • British Columbia, Canada
    • Posts 1,037

    That is correct - However you will want to watch out for using floating as other elements afterwards can be messed up because of it.

     Throw a:

    <div style="clear:both;"></div> afterwards to cancel the effects that floating has on the following elements.

    The Killer Ninja Coding Monkeys thank those that mark helpful posts as answers.

    My Site | My Examples | My Blog
  • Re: Problems with label:Width in Firefox

    12-13-2006, 12:48 PM
    • Loading...
    • Dejan Vesic
    • Joined on 12-04-2006, 10:08 PM
    • Belgrade, Serbia
    • Posts 461
    Yes, you are right, forgot about clearing floats afterward Yes
    Regards,
    Dejan Vesić

    MCAD for .Net technologies | http://www.vesic.org/english/ | Blog: http://www.vesic.org/english/blog/
  • Re: Problems with label:Width in Firefox

    12-13-2006, 1:31 PM
    • Loading...
    • mcmcomasp
    • Joined on 03-08-2004, 4:45 PM
    • Toronto
    • Posts 1,357

    can you also use Columns="30" to produce the correct width in FF as well ?

    mcm

  • Re: Problems with label:Width in Firefox

    12-14-2006, 6:32 AM
    • Loading...
    • avida
    • Joined on 09-17-2005, 3:07 PM
    • Posts 38

    Hi that works fine, but let me add the complication that I am having - This seems to happen if you use themes.

    So set up a theme and add

    <

    asp:Label runat="server" width="250px" skinid="myLabel" />

    so on your page you have

    <

    asp:Label ID="Label1" runat="server" Text="Text 1:" SkinID="myLabel"/> textbox <br />

    <

    asp:Label ID="Label2" runat="server" Text="This is Text 2:" SkinID="myLabel"/> textbox <br />

     When you view the html dot net has rendered , it looks like

    <span id="Label1" style="display:inline-block;width:250px;">Text 1:</span> textbox <br />
    The "display:inline-block;" is recognised by IE but not firefox and no amount of css allows me to override what dot net has rendered.

    Any Ideas ?

     Thanks

  • Re: Problems with label:Width in Firefox

    12-14-2006, 6:47 AM
    • Loading...
    • Dejan Vesic
    • Joined on 12-04-2006, 10:08 PM
    • Belgrade, Serbia
    • Posts 461
    Could you please paste here definition for myLabel from Skin file?
    Regards,
    Dejan Vesić

    MCAD for .Net technologies | http://www.vesic.org/english/ | Blog: http://www.vesic.org/english/blog/
  • Re: Problems with label:Width in Firefox

    12-14-2006, 6:58 AM
    • Loading...
    • avida
    • Joined on 09-17-2005, 3:07 PM
    • Posts 38

    Hi

    Here it is

     <asp:Label runat="server" width="250px" skinid="myLabel" />

     Thanks

  • Re: Problems with label:Width in Firefox

    12-14-2006, 7:39 AM
    • Loading...
    • Dejan Vesic
    • Joined on 12-04-2006, 10:08 PM
    • Belgrade, Serbia
    • Posts 461

    You can try same as in example:

    - add CssClass to definition of label in Skin file
    - add definition in external CSS file.

    However, if this has purpose of creating good looking form, please try to spend some time on examining proper way to do it:

    http://www.quirksmode.org/css/forms.html

    It is very easy, effective and displays properly in all compliant browsers.

     

    Regards,
    Dejan Vesić

    MCAD for .Net technologies | http://www.vesic.org/english/ | Blog: http://www.vesic.org/english/blog/
  • Re: Problems with label:Width in Firefox

    12-14-2006, 8:32 AM
    • Loading...
    • avida
    • Joined on 09-17-2005, 3:07 PM
    • Posts 38

    Thanks for all that.

    But, I suppose the conclusion is that the WIDTH property of the label control is not cross browser compatible.

    It only works with IE and therefore I think this should be pointed out in the MS documentation.

    Or is there a way to make it cross browser compatible ?

  • Re: Problems with label:Width in Firefox

    12-14-2006, 8:42 AM
    • Loading...
    • Dejan Vesic
    • Joined on 12-04-2006, 10:08 PM
    • Belgrade, Serbia
    • Posts 461

    Well, label is server side (so it is ASP.NET thing) and gets rendered to <span> client side element.

    Yes, if you do not change display mode of span element, width has no effect by standards. Only way is above - change display mode to block, add width, and add clearing div at the end. 

    Regards,
    Dejan Vesić

    MCAD for .Net technologies | http://www.vesic.org/english/ | Blog: http://www.vesic.org/english/blog/
  • Re: Problems with label:Width in Firefox

    12-14-2006, 11:44 AM
    • Loading...
    • RTernier
    • Joined on 06-05-2003, 1:40 AM
    • British Columbia, Canada
    • Posts 1,037
    avida:

    Thanks for all that.

    But, I suppose the conclusion is that the WIDTH property of the label control is not cross browser compatible.

    It only works with IE and therefore I think this should be pointed out in the MS documentation.

    Or is there a way to make it cross browser compatible ?

    The Killer Ninja Coding Monkeys thank those that mark helpful posts as answers.

    My Site | My Examples | My Blog
  • Re: Problems with label:Width in Firefox

    12-14-2006, 11:47 AM
    • Loading...
    • RTernier
    • Joined on 06-05-2003, 1:40 AM
    • British Columbia, Canada
    • Posts 1,037
    avida:

    Thanks for all that.

    But, I suppose the conclusion is that the WIDTH property of the label control is not cross browser compatible.

    It only works with IE and therefore I think this should be pointed out in the MS documentation.

    Or is there a way to make it cross browser compatible ?

    Avida, you're right - only IE Supports that because IE is a MS product. MS has wisened up a bit after the release of ASP.NET and has started gearing it's Developer Solutions towards multiple browsers.

     You will also see that most web developers do not use width/height tags (attributes) in the HTML control - instead we use the style/class attribute.  I'd recommend not using width/height attributes and use the class attribute and build CSS classes to be used by your web applications.

     But for now... yea width will only work in IE because IE doesn't follow W3C CSS Standards totally, firefox doesn't follow all of them but adheres to them more than most other browsers.

    The Killer Ninja Coding Monkeys thank those that mark helpful posts as answers.

    My Site | My Examples | My Blog
  • Re: Problems with label:Width in Firefox

    12-15-2006, 8:12 AM
    • Loading...
    • blumonde
    • Joined on 03-11-2006, 8:45 PM
    • US
    • Posts 417
    Dejan Vesic:

    If you need someone to blame, blame IE Smile

    Let me explain: Label gets rendered in <span> element; by W3C standard, <span> element is of type inline, so it does not have width (it is not applicable to it).

    So, Firefox and other browsers render label correctly. If you do want that kind of behaviour, you can do following:

    Create CSS class which will be applied on labels which needs width:

    .fixedLabel 
    {
        display: block;
        float: left;
    }

     Now, give to your labels this CssStyle:

    <asp:Label ID="label1"  CssClass="fixedLabel" runat="server" Text="This is label 1" width="250px" /><asp:TextBox
        ID="TextBox1" runat="server"></asp:TextBox><br/>
    <asp:Label ID="label2" CssClass="fixedLabel" runat="server" Text="This is another label" WIDTH="250px" /><asp:TextBox
        ID="TextBox2" runat="server"></asp:TextBox><br/>
    

     

    and display should be ok in all compliant browsers.

    Hi Dejan,

    I am having a problem with the label width as well. I added

    display: block;

    float: left;

    to my css class and the text of the label control field is display as a long straight line. It doesn't wordwrap. I need the text wordwrap. Any ideas?

    Below is the css class:

    .Label

    {

    color: #dcdcdc;

    width: 585px;

    display: block;

    float: left;

    }

    Thanks.

    blumonde

    Cheers
    no pain no gain
  • Re: Problems with label:Width in Firefox

    12-15-2006, 8:58 AM
    • Loading...
    • Dejan Vesic
    • Joined on 12-04-2006, 10:08 PM
    • Belgrade, Serbia
    • Posts 461

    You can't fix width and also require word-wrap :-)

    I am not sure how can you resolve this. 

    Regards,
    Dejan Vesić

    MCAD for .Net technologies | http://www.vesic.org/english/ | Blog: http://www.vesic.org/english/blog/