a few important CSS tricks

On 11-9-2004, in Coding, CSS, by Alex

Ten CSS tricks you may not know

and

Ten CSS tricks — corrected and improved

Well, no news for me at all but it is really good to have them in one place.
I would like to add there some

  • :hover directive trick for any element (using IE CSS behavior): div#myDiv {behavior: url(h.htc)};
    div#myDiv.hover, div#myDiv:hover {border: 1px solid red;}
    – better to add some default class also 🙂
  • xhtml [xmlns] hack for Mozilla browsers: at the top or css doc just add
    [xmlns] {};
    div#myBlock {background-color: green;} /* for IE, Opera etc */
    [xmlns] div#myBlock {background-color: red;} /* for Mozilla Gecko Only */
    . NB: Works only for xhtml
  • fieldsets & labels using for forms instead of tables (very useful)
  • input[type="submit"] {background-color: red;} /* for non-IE */
    input {background-color: black; background-color: expression(this.type=='submit'?'red':'black');} /* for IE */
  • oveflow: -moz-scrollbars-vertical; for Mozilla scroller
  • html,body {padding: 0; margin: 0;}
    div#fxd {
    position: fixed !important;
    position: absolute;
    top: 25px;
    left: 15px;
    top: expression(body.scrollTop+25+'px');
    }
    for position: fixed emulation on IE
 

Comments are closed.