View Poll Results: Do you use CSS hacks?

6. You may not vote on this poll
  • Yay hacks!

    1 16.67%
  • Boo hacks! Yay conditional comments!

    1 16.67%
  • I use the ultimate hack: Tables.

    0 0%
  • I can get things to work just fine without hacks, tables or conditional comments.

    4 66.67%
Results 1 to 15 of 16

Thread: CSS and Internet Explorer: To Hack or Not To Hack?

Threaded View

  1. #1
    Join Date
    Feb 2003
    Michigan, USA

    CSS and Internet Explorer: To Hack or Not To Hack?

    We see discussions every once in a while about table-based layouts versus CSS and DIVs, but I haven't seen a thread about the benefits and disadvantages of using CSS hacks, or filters. Let that be this thread

    First and foremost, I want this to be educational and a discussion utilizing facts. Link to articles, studies, etc. If you post something that's not backed up with facts, point out that it's your opinion. And opinions are welcome, but I don't want this to degrade to a fist fight. That said...

    What is a CSS hack?

    Simply put, a CSS hack, sometimes called a CSS filter, is writing CSS styles that take advantage of browser support for style sheets and bugs in how browsers read style sheets. You give one browser a certain property and value, then use some sort of hack to give another browser a different value. A small example is in order.
    .foo {
     color: red;   /* Hide from IE5-Mac: \*/
     color: green; /* End IE5-Mac hiding */
    This particular hack takes advantage of an Internet Explorer 5/Mac bug where the backslash character escapes the following character. To IE5-Mac, the asterisk after the backslash simply doesn't exist. The CSS comment remains unclosed in IE5-Mac until the next occurrence of "*/" -- effectively hiding the color: green; property and value. IE5-Mac shows red text. All other browsers show green text.

    Why are CSS hacks used?

    Certain browsers *cough* Internet Explorer *cough* have bugs in how they support cascading style sheets. Sometimes the browser was simply programmed wrong. In either case, a CSS hack is used to correct differences in how certain browsers render the same CSS.

    What are the advantages of using CSS hacks?

    * Allows you to write one CSS file that works in all browsers

    * Fewer CSS files to download means fewer trips to a busy server, which means the page will load faster (and it's less stress on a busy server).

    * With care, hacks can be written to prevent problems with future versions of a browser.

    * One CSS file is easier to update.

    What are the disadvantages of using CSS hacks?

    * You may run into problems with future versions of a browser.

    * Sometimes the hacks use proprietary CSS properties.

    * A hack for one browser may be recognized by a future version of a different browser, effectively breaking the style sheet.

    * Hacks can add unneeded bulk to a style sheet.

    * Multiple hacks can be a nightmare to interpret in the future.

    What are the alternatives to using CSS hacks?

    Since hacks are almost always written to get Internet Explorer to behave properly, a good alternative is using conditional comments that are only recognized by Internet Explorer, and allow you to import IE-only style sheets that contain the styles needed to get Internet Explorer working.

    Then you've got your main style sheets that all browsers import. CSS is written to specification. The style sheets imported using conditional comments contain all the incorrect values that IE needs in order to function. But then you've got two style sheets where there only used to be one.

    My thoughts on CSS hacks

    Hooray for hacks. I don't like going hack crazy, mind you. But I won't shy away from a hack if it gets the job done. My prefered method is to use as few hacks as possible. Since most IE-Win bugs can be cured by invoking the hasLayout property, I tend to give things set widths and not just relying on a block element taking up the correct width. If a width doesn't work, I use the proprietary Internet Explorer property and value zoom: 1;

    I admit. I used to employ the Holly Hack quite a bit, but with Internet Explorer 7 not supporting the star-html hack, and supporting the child selector, the Holly Hack will become useless. In hindsite, I wish I hadn't used it. But zoom: 1; seems harmless, and probably always will be. Right? Right? Tough decision.

    Now, I'd like to know all of your thoughts.
    Last edited by toicontien; 04-07-2006 at 03:12 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.21164 seconds
  • Memory Usage 3,765KB
  • Queries Executed 15 (?)
More Information
Template Usage (34):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (3)bbcode_code
  • (2)bbcode_html
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (16)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)pollresult
  • (1)pollresults_table
  • (16)postbit
  • (16)postbit_onlinestatus
  • (16)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (27):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./includes/functions_threadedmode.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (76):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • showthread_poll_start
  • showthread_polloption
  • showthread_poll_complete
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates