Results 1 to 7 of 7

Thread: Standards-compliant cross-compatibility

  1. #1
    Join Date
    Nov 2004
    Location
    John Abbott College, Montreal, Canada
    Posts
    79

    Default Standards-compliant cross-compatibility

    I've been working on the problem of absolute compatibility for a while now. I've never found a simple, straight-forward tutorial to do this (though I haven't really looked; the challenge keeps me entertained :P), so for any curious or ambitious webdesigners I'll give a few pointers I've discovered.

    Fixing IE for Windows
    First, Internet Explorer. It's evil. Pure evil. If you forget about it, cross compatibility is easy. Unfortunately, W3School statistics estimate that 75.1% of users browse with Internet Explorer 5.5 or 6. Considering that IE for Windows interprets the box model (among other things) differently than other browsers, this can be a little problematic. Fortunately, it's so evil that even Microsoft had to notice eventually, and there is a conditional 'comment' that works with Internet Explorer 5+.

    Code:
    <!--[if IE]>
    <style type="text/CSS">
    
    .ie-topboxfix {
    	margin-top: .6em;
    	}
    </style>
    
    <![endif]-->
    The above code is on my (experimental) website and is used to fix a problem in which Internet Explorer will render text partially outside it's paragraph container and refuse to display it under certain conditions. The important parts are the first and last lines. All other browsers will see the and see it as a comment, thus will ignore it entirely. This can contain any code (PHP, text, HTML, CSS, etc). However, since the conditional statement is HTML, it can't be inserted anywhere HTML can't be inserted; a CSS stylesheet, for example. The solution is usually to put it in the HTML file itself (as in the first example), and perhaps use server-side includes to insert it easily into multiple pages.

    Since CSS is, by definition, cascading, you can use this feature to supercede the proper code with the IE code. For example, you can use CSS to position your boxes one way, then follow the proper code with this conditional statement that gives IE it's dose of quirkiness. The biggest benefit of this is that it is not a hack; it doesn't rely on a bug to fix a bug, and thus can't produce undesirable effects in other browsers or in a hypothetical future version of the browser it's intended to fix. A secondary benefit is that since it's technically a comment, it's standards-compliant; it validates as proper XHTML Strict (or whichever version of HTML you use).

    Relative text
    There are many ways to be cross-resolution compatible (shortened to CRC because I'm lazy), but nearly all of them involve either having multiple versions of something or other, or using scripts. Multiples versions of anything are an unnecessary hassle, and scripts require either than the user have or allow that script (as in the case of javascript) or that your server be compatible with or allow that script (as in the case of PHP). There's a (debatably) easier way to do it. The key, when you think about it, is relativity. There are only two relative units, and these are percentages and ems. Guess which units you should use?

    An em is equal to the default font size of the user's browser. In most browsers, that is 16px, so 1em=16px. Font size can be easily rendered CRC by using ems, especially if you use CSS. For example, consider the following hypothetical code (off the top of my head, please correct me if you see errors):

    Code:
    <style type="text/CSS">
    h1   {font-size: 2em;}
    h2   {font-size: 1.6em;}
    h3   {font-size: 1.2em;}
    h4   {font-size: 1em;}
    h5   {font-size: .6em;}
    </style>
    
    (...)
    <div class="blah">
           <h1>Some Section Title</h1>
           <h2>Some Subtitle</h2>
           <h3>Some important text.</h3>
           <h4>Normal text.</h4>
           <h5>Footnote... or something.</h5>
    This will result in the section title being twice the default font-size, the subtitle 1.6 times the default font-size, et cetera. You can combine this with other CSS properties like text-decoration to achieve the results you want. This is important because (a) the default font-size is generally the optimal reading size for that browser and operating system, and (b) this type of unit can be resized in all browsers. Go ahead, try it; you'll notice most of the font on this forum can't be resized (unless you use a standards-compliant browser like Firefox).

    Relative boxes
    Boxes, in this case, refers to any block element (paragraphs, divs, spans, images, et cetera). As you may have guessed, the unit you'll be using here is percentages. The important detail about this is that they (should) be relative to their container (example later). Let us say you want two columns on your screen with a margin on the edges and between them. You want these two columns to look exactly the same on any resolution, from the 1280x1020 insane person to whatever resolution those cell phones have. To do this, you can use code somewhat like this:

    Code:
    <style type="text/CSS">
    .column-left {
            float: left;
            margin-left: 3%;
            width: 45%;
            }
    
    .column-right {
            float: right;
            margin-right: 3%;
            width: 45%;
            }
    </style>
    <div class="column-left">Blah.</div>
    <div class="column-right">Blah.</div>
    This code should make each column precisely 45% of the window width (you can see this by resizing your window), with a 3% outer margin and 4% inner margin (improper terms, but you know what I mean -.-). The percentages are relative to the window, since only the body and HTML tags contain them. If you were to create div elements within those div elements (nest them), their sizes would be relative to their parent div elements.

    And that's about it. Just experiment with those three concepts (screwy IE fix, relative text, and relative boxes) and you should be able to design a completely fluid, cross-browser design. The only problem with this design (inevitably) is that it's only compatible with browsers beginning around 1999 to 2000. This shouldn't be a problem; people are slow to update, but not (usually) that slow.

    I'm designing my new website using all the above points as well as several others, and it'll include a section for webdesign tutorials and a forum for help with those tutorials. Feel free to ask questions, point out mistakes, make suggestions, et cetera; in the spirit of open source, everyone can contribute and will be fully credited in the tutorial. I'll correct this tutorial as improvements are brought up. :)

  2. #2
    Join Date
    Oct 2004
    Posts
    50

    Default Re: Standards-compliant cross-compatibility

    Quote Originally Posted by Pathoschild
    (off the top of my head, please correct me if you see errors)
    Not a single one.

    I would like to add up a few lines here. One may wish to go even a bit further and want to make sure also his images scale with the text. To this end, suppose we have an image MYIMGAGE.GIF included with the following HTML code:
    Quote Originally Posted by HTML code
    [img]path/to/the/image/MYIMAGE.GIF[/img]
    As the size is not specified with WIDTH and HEIGHT, the image will be displayed in its natural size, lets assume it is 100x100px. In order to make it scablable, you can use the following CSS lines
    Quote Originally Posted by CSS code
    <style type="text/css">
    .ScIm { width: 10em; }
    </style>
    In this way the width of the HTML element having a class attribute value ScIm will be 10em (meaning 10 times the height of the letter M). So if you scale the text (CTR/scroll or CRT/+- in most browsers), the image will also scale.

    Similarly, suppose you have a two-column layout with the left column taking 10% of the window and the right one taking the remaining 90% (see, e.g., Pathoschild's post above on how to achieve it). Suppose further that in the left column you have an image, again our MYIMAGE.GIF. If you leave the origilal 100x100px image size unchanges, then it can become wider than the left column when the window is reduced to a size of less than 1000px (since the left column is 10% of it). To avoid such an unwanted effect, you can define the width of the image as 100%, i.e.
    Quote Originally Posted by CSS code
    <style type="text/css">
    .ScIm { width: 100%; }
    .column-left {width: 10%; }
    </style>
    It will then fill up the width of the div-element that contains it:
    Quote Originally Posted by HTML code
    <div class="column-left">
    [img]path/to/the/image/MYIMAGE.GIF[/img]
    Bla-bla
    </div>
    Note that when specifying image sizes it is advisable you only specify the height OR the width, but not both. In this way you make sure the proportions remain unchanged...

  3. #3
    Join Date
    Nov 2004
    Location
    John Abbott College, Montreal, Canada
    Posts
    79

    Default

    Interesting suggestions. I've partially completed the general layout of my website, which I'm using to experiment with this. I will upload it to my website when I've finished off a few details (the 'experimental' website currently uploaded is an older, now obsolete version). As it is now, the page will scale to fit the window, which fits my first goal. It is so far written entirely in standards-compliant XHTML Strict and CSS, with very little markup. It will be fully customisable with interchangeable stylesheets, which meets my second goal.

    However, I'm currently facing a problem with my third goal: cross-browser compatibility. Besides a few IE glitches which will be corrected with an ie-only stylesheet overriding some of the standard stylesheet, only one major problem remains: the alpha transparency mentioned in another thread (General Discussion >> India will beat China by 2025). Internet Explorer remains a problem, displaying an ugly silver background behind semitransparent images. This should be fixed with a PHP script described at Koivi.com in the article "Normal display of PNG Alpha Transparency with MSIE" (http://www.koivi.com/ie-png-transparency/).

  4. #4
    Join Date
    Oct 2004
    Posts
    50

    Default my turn

    guess its my turn to say something :)
    i have now php :) but completely no time to start making use of it. :( And no time to update my site and add up the info i was planning to place. :( Busy, busy, busy!

    Anyway: Talking about websites with interchangable layout by means of different cascading style sheets, the following link might be of interest to people wandering what can be achieved by just using a different CSS on the same HTML file:
    http://www.csszengarden.com/
    Check it out guys, you'll like it (i can give you a "money-back guarantee":) )

    About the "php-based png transparency solution": this is nothing but server-side translation of the client-side javascript solution: you just detect the browser and if IE you add up a line using the IE's alpha transparency filter everywhere a png file is included. Don't say its a bad solution: of course solutions based on server-side scripting are always preferable to client-side ones since the later can be disactivated by the user... BUT, when using free hosting one most often cannot make use of server-side scripting, so this has also its disadvantages (just like everything else).

  5. #5
    Join Date
    Nov 2004
    Location
    John Abbott College, Montreal, Canada
    Posts
    79

    Default

    I've been there before. That's some incredible CSS. I was looking at the site a few days ago, and I learned something! :D I looked at the source code and found out we could 'specialise' (for lack of better verb) classes, which made it much easier to design my own CSS.

    Code:
    p {
      line-height: .8em;
      margin-top: 0em;
      font-size: 1em;
      }
    
    #footer p {
              font-size: .4em;
              margin-top: 1em;
              margin-bottom: 0em;
              margin-left: auto;
              margin-right: auto;
              }
    
    <div class="message">
    
    
    Blah.</p>
    </div>
    
    <div id="footer">
       
    
    Bleh.</p>
    </div>
    As usual this is off the top of my head, so correct me if you see any errors. Accuracy in this case isn't important anyway. The first class will be applied to all p elements on the page, and the second will be applied to all p elements with id="footer".

    yay! No more classes everywhere! :D

    I've been there before. That's some incredible CSS. I was looking at the site a few days ago, and I learned something! :D I looked at the source code and found out we could 'specialise' (for lack of better verb) classes, which made it much easier to design my own CSS.

    Code:
    p {
      line-height: .8em;
      margin-top: 0em;
      font-size: 1em;
      }
    
    #footer p {
              font-size: .4em;
              margin-top: 1em;
              margin-bottom: 0em;
              margin-left: auto;
              margin-right: auto;
              }
    
    <div class="message">
    
    
    Blah.</p>
    </div>
    
    <div id="footer">
       
    
    Bleh.</p>
    </div>
    As usual this is off the top of my head, so correct me if you see any errors. Accuracy in this case isn't important anyway. The first class will be applied to all p elements on the page, and the second will be applied to all p elements with id="footer".

    yay! No more classes everywhere! :D


    Back to the topic, though. I always prefer server-side scripting. For one, it's one of those wonderful things that's universally compatible with all browsers and operating systems. The results may not be (ie, images for a text browser), but the script is; if only CSS was like that! It also benefits dialup users because the script isn't slowed by their slower connection, and there's no server to client to server to client process; it's server to client, period.

  6. #6
    Join Date
    Oct 2004
    Posts
    50

    Default classes

    Quote Originally Posted by Pathoschild
    Code:
    p {
      line-height: .8em;
      margin-top: 0em;
      font-size: 1em;
      }
    
    #footer p {
              font-size: .4em;
              margin-top: 1em;
              margin-bottom: 0em;
              margin-left: auto;
              margin-right: auto;
              }
    
    <div class="message">
    
    
    Blah.</p>
    </div>
    
    <div id="footer">
       
    
    Bleh.</p>
    </div>
    yay! No more classes everywhere! :D
    Yeah, you can reduce the number of classes by 1 this way. Clearly, if you have more than one classes for a div element, for instance, you cannot remove them all, can you? Otherwise we wouldn't use classes. But what's wrong about classes enyway?

  7. #7
    Join Date
    Nov 2004
    Location
    John Abbott College, Montreal, Canada
    Posts
    79

    Default

    Code:
    <div id="menubar">
            <p class="menuitem">Menu Item 1</p>
            <p class="menuitem">Menu Item 2</p>
            <p class="menuitem">Menu Item 3</p>
            <p class="menuitem">Menu Item 4</p>
            <p class="menuitem">Menu Item 5</p>
            <p class="menuitem">Menu Item 6</p>
            <p class="menuitem">Menu Item 7</p>
    </div>
    
    <div id="stylebar">
            <p class="menuitem">Stylesheet 1</p>
            <p class="menuitem">Stylesheet 2</p>
            <p class="menuitem">Stylesheet 3</p>
            <p class="menuitem">Stylesheet 4</p>
            <p class="menuitem">Stylesheet 5</p>
    </div>
    Ouch. That. -.-

    A much more efficient way is to use a hierarchy. For example...

    Code:
    <div id="menubar">
            <h1>Navigation</h1>
            <h3>Menu Item 1</h3>
            <h3>Menu Item 2</h3> ...
    </div>
    After all, the entire point of CSS is to reduce markup to the strict minimum. By assigning a hierarchy such as the one above and defining it in the CSS, you accomplish this. By assigning common properties to group classes, you can reduce it even further.

    Code:
    h2, h3, h4, h5      {font-weight: normal;font-family:Sylfaen, "sans serif"; margin-top: 0px;margin-bottom:0px;}
    
    #menubar h1, #stylebar h1   {font-size: 1.3em;}
    #menubar h3, #stylebar h3   {font-size: 1em;}

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
  •