Jump to content


Photo

Conditional Comments or Hacks?


  • Please log in to reply
7 replies to this topic

#1 LSW

LSW

    Knight of the Square Cubicle

  • Moderators
  • 8,017 posts
  • LocationJuneau AK

Posted 21 December 2008 - 09:45 PM

This is not a right or wrong thread, just two way of doing things and the reason for that.

So hacks are bad - most of us agree. A hack is a code style that takes advantage of bugs and mistakes in browsers. If the browser is fixed, the hack does not work and the site is likely broken.

Discussing this in another forum a comment was made that rings true and should be mentioned here. So a few points to consider:

Hack

Con - Requires a mistake or bug in a browser to work, it that is fixed the hack fails.


Con - Makes the CSS not valid


Pro - A hack is placed alone in the CSS, when the CSS is external this means you need but remove it from the style sheet to be rid of it.




Condition Comments


Con - They have to be placed in your markup, every single page...


Con - They muck up pure structured code & invalidate your code


Con - You are playing to the whims of the most popular browser yes, but you are writing incorrect code due to one single user agent out of the dozens that you may have visit
your site, logical to cater to one single broken user agent?


Pro - You are creating styles for IE in a form that only IE will read leaving your CSS pure for standards based browsers.


Conclusion
The choice is yours, would you rather have pure structure or pure CSS?

Would you rather write a hack in a single document or would you rather write a comment/s in every page of your site? Course with the smart use of Templates or includes you can limit this.

So this is not a do or do not, simply consider this and what comments will follow and make an informed decision whether to use Hacks or Comments. IE7 has improved but there are still some problems with IE7 and Opera 9 and a whole new series of Hacks will be needed. IE7 has blocked the * html hack which was often used to correct Layout problems in IE, however those layout problems have not been corrected, they still exist bit the hack does not.
  • 0

 

Thank You, Migwetth, Gunalche’esh, Ha’w'aa, Danke
 

"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works.
 Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it.
 Anything invented after you're thirty-five is against the natural order of things."
 
                                                                                                                                                    - Douglas Adams from - The Salmon of Doubt (2002)


 


#2 LSW

LSW

    Knight of the Square Cubicle

  • Moderators
  • 8,017 posts
  • LocationJuneau AK

Posted 22 December 2008 - 12:54 PM

:rolleyes:
  • 0

 

Thank You, Migwetth, Gunalche’esh, Ha’w'aa, Danke
 

"Anything that is in the world when you're born is normal and ordinary and is just a natural part of the way the world works.
 Anything that's invented between when you're fifteen and thirty-five is new and exciting and revolutionary and you can probably get a career in it.
 Anything invented after you're thirty-five is against the natural order of things."
 
                                                                                                                                                    - Douglas Adams from - The Salmon of Doubt (2002)


 


#3 p4c

p4c

    New member

  • New Members
  • 5 posts

Posted 08 January 2010 - 06:16 AM

I have a need to do a few things first i wanted to be able to send php code to multiple browsers but not the same code. I ran into a problem with this and on top of that, i wanted to send multiple stlyesheets to different browsers. CC's worked for the second task but I had to make a few "new" hacks to get them to serve my purposes with PHP. These "hacks" that i have created are designed to target 3 browsers, and differientiate between the 3. 2 of which are not IE, meaning firefox, and Google Chrome; using these following "hacks" in conjunction with a "" allows one to distinguish and pass different (x)HTML, CSS and PHP data to the browsers.

I have these set up in a seperate php file than the actual "index" file of the webpage and they are included by employing a SSI. Below is a copy of that file.

Detect IE, firefox and chrome hacks by : p4c - nick gibson

i hope these will be some help and service to others. they are for me.:)

-------------------------------------------------------------here is the file----------------------------------------------------------------------






















You are using Google Chrome.








SOMETHING SHOWN ONLY TO CHROME.'; ?>





SOMETHING SHOWN TO CHROME AND FIREFOX.
'; ?>

________________________________________end of file__________________________________________________



it is my hope that these will perhaps suppliment the * html hack that no longer works, due to IE7.

another thing is that chrome doesnt like background-image styles from imported sheets, but if you append

the holy * html hack like so the issue goes away.

/* Hides from IE5-mac \*/
* html body{height: 1%;} /* ENABLES CHROME TO BE CSS2 COMPLIANT */
/* End hide from IE5-mac */


good day, and god bless -- keep coding keyboard samuris
  • 0

#4 asdfghjkl

asdfghjkl

    Member

  • New Members
  • PipPip
  • 27 posts

Posted 19 April 2010 - 05:02 AM

I'm new familiar with 'Conditional Comments or Hacks'. May be it helpful for me in future. Thanks.
  • 0
web design

#5 Guest_Paul Stephen

Guest_Paul Stephen
  • Guests

Posted 05 May 2011 - 08:26 AM

I am a fresher in design and also 1st time hear about "Conditional Comments or Hacks" here.nicely posted...
  • 0

#6 Ken Peterson

Ken Peterson

    New member

  • Member
  • 12 posts
  • LocationSaint Petersburg

Posted 23 June 2011 - 04:34 AM

This is not a right or wrong thread, just two way of doing things and the reason for that.

So hacks are bad - most of us agree. A hack is a code style that takes advantage of bugs and mistakes in browsers. If the browser is fixed, the hack does not work and the site is likely broken.

Discussing this in another forum a comment was made that rings true and should be mentioned here. So a few points to consider:

Hack

Con - Requires a mistake or bug in a browser to work, it that is fixed the hack fails.


Con - Makes the CSS not valid


Pro - A hack is placed alone in the CSS, when the CSS is external this means you need but remove it from the style sheet to be rid of it.




Condition Comments


Con - They have to be placed in your markup, every single page...


Con - They muck up pure structured code & invalidate your code


Con - You are playing to the whims of the most popular browser yes, but you are writing incorrect code due to one single user agent out of the dozens that you may have visit
your site, logical to cater to one single broken user agent?


Pro - You are creating styles for IE in a form that only IE will read leaving your CSS pure for standards based browsers.


Conclusion
The choice is yours, would you rather have pure structure or pure CSS?

Would you rather write a hack in a single document or would you rather write a comment/s in every page of your site? Course with the smart use of Templates or includes you can limit this.

So this is not a do or do not, simply consider this and what comments will follow and make an informed decision whether to use Hacks or Comments. IE7 has improved but there are still some problems with IE7 and Opera 9 and a whole new series of Hacks will be needed. IE7 has blocked the * html hack which was often used to correct Layout problems in IE, however those layout problems have not been corrected, they still exist bit the hack does not.

Thank you. Its helpful to me.
  • 0

#7 Andrea

Andrea

    Advanced Member

  • Moderators
  • 5,672 posts
  • Facebook:https://www.facebook.com/aandbwebdesignAB
  • LocationSan Antonio, TX

Posted 23 June 2011 - 05:49 AM

Thank you. Its helpful to me.


Keep in mind htat this was written in 2008 - so a couple IE versions ago. Things are different for IE7 and newer than they were for 6 and under.
  • 0

#8 bsmbahamas

bsmbahamas

    New member

  • New Members
  • 9 posts
  • LocationBahamas

Posted 06 January 2012 - 06:43 PM

i really liked this post.

personally i don't use hacks or conditionals but then again i don't have to support IE,
and when i do, i stick to a subset of css that i already know works well in all the major
browsers including IE.

if i really had to though as you suggest, i'd use an include file, and if need be
just wrap it in an if( file_exists('file-name.php) ){ include 'file-name.php'; },
so i could simply delete the include file later and the site would just ignore the
call to include().
  • 1
"We are what we repeatedly do. Excellence, therefore, is not an act, but a habit." -- Aristotle: was a Greek philosopher




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users