Where to place HTML5 fix for IE? - html

I am using this code to make HTML5 tags available to older browsers:
<script>
'header nav aside article footer section'.replace(/\w+/g, function (n) { document.createElement(n) })
</script>
Some sources say to place the code in the head section of the HTML document, and some in the body. Which way is correct?

This script needs to run before IE tries to style the elements in question to avoid the flash of unstyled content. Put it at the bottom of the head tag. See also http://en.wikipedia.org/wiki/Flash_of_unstyled_content and http://modernizr.com/docs/#installing

The most popular way to polyfill this behavior is to use the HTML5Shiv. It recommends the following:
Insert minified distribution shiv in <head> element (after or before your CSS):
<!--[if lt IE 9]>
<script src="dist/html5shiv.js"></script>
<![endif]-->
I’d recommend this shiv rather than rolling your own, as it is kept up to date with new HTML features, such as the fairly recent main element.

Related

HTML5 template not working on Internet Explorer, how to solve it?

I made a template in HTML5 which is working with Chrome and Firefox but not working with Internet Explorer (tested on IE 8).
How can I solve this problem?
just add "display:none" to your templates. Works for i.e. 11
<template id="fancyTemplate" style="display:none"></template>
I recommend you Neovov's polyfill:
https://github.com/neovov/template-element-polyfill
NB: There's a bug in IE 11: it moves <template> under the <body> element before rendering the DOM! So the parentNode attribute is wrong, and nesting will fail.
You can see it in the [F12] Tool.
Get a copy of html4shiv, and use it where IE is less than 9:
<!--[if lt IE 9]>
<link rel="stylesheet" href="styles/ie.css" type="text/css"> <script src="scripts/ie/html5shiv.min.js"></script>
<![endif]-->
You are searching for the html5shiv.
It 'enables' all the html5 elements, which aren't available in the old internet explorer versions.
You can try to replace <template> tag by <script>
<script id="fancyTemplate"></script>
You can hide the element using CSS: template { display:none !important; }
And if you need to access/clone the content like natively possible in other browsers, use this polyfill: https://github.com/jeffcarp/template-polyfill
But keep in mind the content of the <template> can still be found in the DOM and is executed - preventing exactly that is the main goal of the tag. No polyfill can stop that from happening, IE is once again slowing down modern web development.

How do I add CSS script to my basic offline html site?

Im using css button generator to create the code for my css button and it generates the css code and the html code used to insert the css code. But I don't what classname to use. I tried
But that shows up blank in the website preview.
And for an offline site with minimal design would it be better to put the buttons inline? The site will be put on a CD. I'm using dreamweaver cs6.
Well i guess you will need to learn basic HTML first. Each HTML document should contain HEAD and BODY tags. In HEAD section you link your CSS file or write your generated CSS style between STYLE tags. Something like:
<style type="text/css">
.button1 {font-size:15px; color: #cccccc; ....}
.button2 {font-size:18px; padding:10px; ...}
</style>
or link your CSS file inside HTML header with:
<link rel="stylesheet" href="/css/your-stylesheet.css">
You can also check here for some basic examples of HTML and structure of HTML documents.
w3schools
With your link you just make a link to your CSS style which will open as a plain text in browser window so you don't really include it. So include CSS style in your HEAD section either by link or to put your CSS classes and everything between STYLE tags. Once you will do this "call" your style in your links like this:
Go to Google
Local file
Thanks guys. Got it to work. I found this question and answer: mmo-champion.com and it made it clear what you guys were saying.
I deleted the <style type="text/css"> and made sure that the class was = to "classname" since that was what it was called in the CSS file because it was unchanged, and then it worked. I think it didn't work because I had the class = "button1" and I also didn't delete that bit of code before.
Gantt charts & project diary
(source: css-tricks.com)
One more thing, because Internet Explorer does not support some elements which work on Chrome or FireFox, there are some special codes for including only IE CSS file (file that works only if IE is identified):
For all the IE versions, use this:
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="file.css" />
<![endif]-->
For X version only:
<!--[if IE 7]>
<link rel="stylesheet" type="text/css" href="file.css">
<![endif]-->
** This code can only be used for IE7. If you want to use the CSS code for other IE version, change "7" in the line !--[if IE 7> to the appropriate version number.
For IE5.5:
<!--[if IE 5.5000]>
<link rel="stylesheet" type="text/css" href="file.css" />
<![endif]-->
For IE6 and lower (including IE6), use if lte IE 6 or if lt IE 7.
For IE7 and higher (including IE7), use if gte IE 8 or if gt IE 7.
Sometimes IE blocks webpages' scripts or ActiveX controls.
To ignore IE block scripts or ActiveX controls, use this line, at the head of the HTML code.
NOT in the <head> tags, at the first line. It's important.
<!-- saved from url=(0014)about:internet -->
To read more about this error, read MOTW.

ie 7-8 does not support object tag?

I created my website's header and footer in a separate html file and I am embedding those files in my web pages.
After all the hard work and completing the website I came across an error in IE8. My header and footer are aligned all over the place in IE7 & 8.
<footer>
<div id="divObjFooter">
<object data="/footer.html" type="text/html">
</object>
</div>
</footer>
Update - fixed for any version running html5
Finally found a way to support ie any version.
<!--[if IE]>
<div id="footer">
<div id="divObjFooter">
<iframe src="footer.html"> </iframe>
</div>
</div>
<![endif]-->
<![if !IE]>
<footer>
<div id="divObjFooter">
<object data="footer.html" type="text/html"> </object>
</div>
</footer>
<![endif]>
ie8 and earlier do not support HTML5 tags (in your case, the <footer> tag), and therefore do not style them. To get around this, you could simply use div's with id's and style them from there, or, if you want to use the latest and greatest HTML5 stuff, you can use an html5 shiv.
I would recommend the script hosted on Google code:
https://code.google.com/p/html5shiv/
Check the website Can I Use for browser support of HTML5 and CSS3 before you use new tags and selectors against your target audience.
IE<10 supports very little (less then 40%) modern html and css. You will likely have to use modernizr or something similar or simply not use the latest "shiny"
To answer first the question in the title: IE has supported the object element since IE 4 (though early implementations were lousy). Your problem does not seem to be with that element but with your styling of the footer element – a completely different issue.
The footer element is not supported by IE 7 and IE 8. This matters little as such, since the default effect would be just making the element content a block, and your content is already a block (a div element). What causes the trouble is that you have some CSS rules that set properties on the footer element. This won’t work on IE 7–8, since they do not recognize the element even in the sense of letting you style it.
There is a quick fix: put the following before your first style sheet or reference to any style sheet:
<script>document.createElement('footer')</script>
This is effectively what many “shims” or “polyfills” or whatever you call them are doing, and if you have an issue with footer only, you might use just the quick fix.
Alternatively, set your CSS rules on the div inside, using the #divObjFooter selector.
P.S. Using object (or iframe) to include a footer is possible, but clumsy. It will include an HTML file in a subwindow of the document window, and links won’t work normally etc. If at all possible, it is better to use server side tools, like Server-Side Includes (SSI) or their more advanced counterparts, or page management software.
<!--[if IE]>
<div id="footer">
<div id="divObjFooter">
<iframe src="footer.html"> </iframe>
</div>
</div>
<![endif]-->
<![if !IE]>
<footer>
<div id="divObjFooter">
<object data="footer.html" type="text/html"> </object>
</div>
</footer>
<![endif]>

Link to Relative StyleSheet tag not working

I am creating a website based from tumblr that seems to work fine on google chrome, but has a issue with the ad box that I have assigned to the right of the page.
I have searched google and found this related question, but the answer given does not work for me.
I have tried the following.
Just adding a html class="ie9" tag with the proper if statements.
Clearing my cache.
And checking the browser mode.
It seems to be just one element of the page. The right side does not show up correctly, but I fiddled with the customization in IE 9 and I have the exact margin reqs. However I can't seem to link the stylesheet.
Is this because I'm linking a static file in this manner?
<!--[if IE 9]>
<link rel="stylesheet" type="text/css" href="http://static.tumblr.com/texnbv5/j70mi1pbq/ie9.css" />
Does this have anything to do with the fact that I am linking this stysheet from a different domain instead of the hosted domain?
Also is there anyway I can just single out the line that needs to be adjusted?
Is it possible for me to place a if statement in the css portion of my site
<!--[if IE 9]<style>#Content-right{margin:-1000}</style>
<![endif]-->
it's not working because you didn't close your comment tag. It has nothing to do with cross-domain css file fetching, which is entirely legal.
<!--[if IE 9]>
<link rel="stylesheet" type="text/css" href="http://static.tumblr.com/texnbv5/j70mi1pbq/ie9.css" />
should be <!-- [if IE 9] -->
Also... what engine is supposed to be acting on this IF?
There is a very interesting article on just this topic. It addresses the need/desire to isolate browser specific CSS without having to create an entire CSS file. There are also a number of benefits to the approach. I have utilized it for a number of years due to my own needs and was unaware until recently that such analysis had been performed on the technique.
Here is the link: Conditional Stylesheets vs. CSS Hacks
Other Things of Note:
Positioning of your Stylesheets is very important in CSS. Since we can't see your other calls and you are using a separate stylesheet, it is important that you place the conditional statement under your standard stylesheet.
Example
<link rel="stylesheet" href="path/to/standard.css" />
<!--[if IE 9]-->
<link rel="stylesheet" href="http://path/to/ie9.css" />
<!--[endif]-->
This is because CSS uses the styles that were loaded last if there is a conflict. I only mention this because it could be affecting you results as it is a common mistake.
Try this code
<!--[if lt IE 9]>
<link rel="stylesheet" href="http://static.tumblr.com/texnbv5/j70mi1pbq/ie9.css" />
<![endif] -->
I hope you work it

Not serving a CSS to IE7 & IE8

Is there an easy way to serve a whole stylesheet to every modern Browser but IE7 and IE8? Some kind of inverted conditional comments?
The following should work per Microsoft's documentation:
<!--[if !((IE 7)|(IE 8))]><!--><link rel="stylesheet" type="text/css" href="ie.css" /><!--<![endif]-->
I don't know much about web coding... but this looks like what you are looking for.
Check out this site.
If you are simply trying to exclude browsers older than IE9, it is simpler to use
<!--[if gte IE 9]>
<link ...
<![end if]-->
Otherwise, you will need to use other operators to fit a specific subset, as others have already provided.
The MSDN docs are very useful here: http://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx
Note that you can use "!" to denote "not". So you could use something like this:
<!-- [if !(IE 7) & !(IE 8)]>
<link href="modern.css" />
<![endif]-->
Pretty straight forward.
Updated
Since IE's quirky conditionals don't get respected in other browsers. You could easily add jQuery to the page and do something like this:
<script src="jquery.js"></script>
<!-- add jquery first for browser sniffing -->
<script>
// if broswer is IE and less than version 9 write out the nice CSS
if($.browser.msie && parseInt($.browser.version) < 9){
document.write("<link href='modern.css'/>");
}
</script>
jQuery docs on browser sniffing: http://api.jquery.com/jQuery.browser/