Handling pseudo-elements ::before and ::after when targeting IE6 IE7 - css

Can any CSS3 experts tell me the best strategy for handling the before and after pseudo elements with IE6 and IE7?

If you use jQuery it is a simple one-liner. Just use prepend() and inject a span with a class .before (for the simplicity of changing the CSS). I've made a fiddle for you.

I write a small script for old IE to add special elements in DOM. (Via IE conditional comments.) The rest of common browsers get this by pure CSS. The downside is I have to write the code twice. The upside, I have IE only code in one place.

Related

Comments produced by ng-repeat break first-child pseudo selector in IE8

It seems that in AngularJS 1.2.13 (and as far back as 1.0.8), the ng-repeat directive creates DOM comments around the repeated elements. This is breaking in IE8 because the first-child is not the element but the comment. Is there a way to suppress the comments in Angular or do they serve a higher purpose? I know I can put a first-child class based on $first in the directive, but I don't want to if I don't have to.
Thanks.
P.S.
I have all proper shims and polyfills and best practices in place otherwise.
Update
IE8 is acting like it is IE7 for some reason, which is triggering this issue. I am still digging into why that is happening.
The problem came about when using IE9.js as a shim, it was somehow making IE8 behave like IE7 rather than IE9, I reduced the ES5 shims down to the bare minimum and now things are working as expected.

How to show/hide content on click with CSS

I have put together this simple code for showing/hiding some content on click using CSS only. It works as I want it to in FF but wont work in Chrome or Safari (untested as yet in IE)
http://jsfiddle.net/fW3yW/
Can someone please tell me why it wont work in these browsers and suggest an alternative (using CSS only if possible)?
Here is the site where the code is being used - http://www.themontessoripeople.co.uk/montesori/?page_id=20#policies-list
Added tabindex, works in Chrome: http://jsfiddle.net/fW3yW/1/
From here: css focus not working in safari and chrome
jQuery method: http://jsfiddle.net/fW3yW/12/
You're abusing CSS. The :focus psuedo-class is meant for styling form elements that have focus, rather than for <a> links, where browsers might implement :focus differently, and then there's also the similar :active psuedo-class.
I suggest you do not hide anything by default with CSS, but use jQuery to hide the elements on-load, then use jQuery to create show/hide animations (easily done with a single line of code) when a link is clicked. It's a lot more elegant and works on more browsers.
You're using a CSS3 selector, with an XHTML doctype. I don't know that all browsers will handle CSS3 with an XHTML doctype tag - though the two specs aren't necessarily tied together.
Have you tried changing the doctype to indicate HTML5? (Then, of course, that brings up all kinds of HTML5shim questions...)
Use jQuery instead...way more reliable and elegant.
http://www.w3schools.com/jquery/jquery_hide_show.asp

Why is it not recommended to use a polyfill for CSS3 selector support?

I need to ensure IE7 and IE8 support.
I'm using a few CSS3 selectors like :last-child. I dropped in Selectivizr, and it appears to fix many problems in those browsers, leaving me just a handful to clean up with some fallback code.
But HTML5 Please recommends using only fallbacks, not polyfills, to address CSS3 selector support:
We strongly recommend you do not try to polyfill this, but if you do need one, you can use Selectivizr.
It would be good to know why they "strongly recommend" against polyfills here... Anyone have any ideas?
Using a fallback I think means you should be adding classes to the elements that you cannot select with modern selectors like adding .first to be used for :first-child, or .checked for :checked, and so on.
I can't think of any reason HTML5 Please recommends not to use polyfills so strongly, except for performance and independence from JavaScript. It's best to depend solely on CSS to style and draw.
But in my humble opinion, Selectivizr is a piece of magic that will teach IE6-8 to behave and ensure your HTML is clean from unnecessary classes and will shorten your development time.

text selectors in css

I am wondering if there are any other selectors which select only part of an HTML element. I know of these two:
:first-letter
:first-line
But AFAIK there are no other selectors which do this. I am interested in any (even browser-specific) selectors or other methods of manipulating only part of a block of text.
The Use Case
I have (more) control over the .css and .js than over the DOM. I've been using js workarounds but want to include any CSS solutions as well, because I don't like to depend of javascript for my styles.
Even if the solution is only supported in konquerer it is still better than nothing IMO.
Nope, those are the only two content pseudo-elements available that select real text nodes. Nothing new has made it into the CSS3 recommendation.
One of the proposals that didn't make it was ::selection (roughly implemented by Opera, Safari and Chrome, and by Firefox as ::moz-selection), but your use case doesn't really say anything about what you want to do so I have no idea if that selector is relevant to your needs.
I'm not aware of any browser-specific pseudo-elements, but there are also the ::before and ::after pseudo-elements. See the CSS 2.1 specification from the W3C.

In CSS, is anchor the only element that supports pseudo style properties?

I was thinking of using these styles for easier cell rollover effects in a datagrid, but I can't seem to get these styles working on anything other than the most basic of tag.
Is the <a> anchor tag the only element in HTML to support styles like hover, active, visited?
It should work on all elements, but IE6 only supports in on links. I used whatever:hover to work around that.
Modern browsers support the pseudo style properties for all elements, IE6 is the only current wide-spread browser that doesn't (and that's only for the :hover property).
It is unfortunate but until IE6 usage drops below minimal levels, you should avoid using the :hover property on non-anchor elements for better cross-browser support. Alternatively, you can provide IE6 support for it using javascript (with browser detection) or CSS expressions.
According to the CSS2 specification:
CSS doesn't define which elements may be in the above states [:hover, :active, and :focus], or how the states are entered and left.
In other words, don't depend on them working at all. I would use Javascript, along with CSS, to get a wider audience.
PPK has a great reference for browser compatibility here: http://www.quirksmode.org/css/contents.html#t16
It shows the browsers that correctly support the :hover pseudoclass (and lots of other css selectors).
Yes unfortunately anchor is the only tag that supports these styles.
I would recommend the following:
Before coding any of your own JS, try use the JQuery framework, it might save you loads of work.
Another crazy workaround would be to expand the size of the using style to 100% of the parent (cell), this way you would effectively be applying the style to the cell.

Resources