Tradizionalmente, abbiamo combattuto contro le incongruenze dei vari browser, aggiungendo codice css specifico per fissare il comportamento non standard.
il problema fino ad ora è stato individuare questi browser e porvi rimedio.
alla prima parte del problema, si può ovviare con i così detti hacks, cioè istruzioni mal formate che vengono interpretate solo in certe circostanze. nelle situazioni più favorevoli l'unico browser di cui occorrerà curarsi sarà IE, per il quale esiste una tecnica specifica, detta commento condizionale, con cui generalmente si include un css apposito.
questo css separato è sempre meglio degli hacks, che sono francamente inleggibili e impossibili da mantenere, ma ancora scomodo perché divide su più files le regole necessarie alla resa corretta della pagina.
una prima evoluzione del problema consiste nel usare i commenti condizionali per taggare il documento, in questo modo possiamo organizzare efficacemente il css.
questa tecnica è efficace, veloce e pulita ma funziona esclusivamente su IE, non funziona per safari ed opera e non distingue le diverse versions of browsers will the operating system.
The natural evolution of this system allows you to reveal every detail of the browser in order to write correct code, clean inspired by this article, I got the following function:
(function () {var u =
navigator.userAgent.toLowerCase (), the
= function (t) {return u.indexOf (t)> -1;},
g = 'gecko', w = 'webkit', c
=[(!(/ opera i (g g +'/')?:
/ opera \\ s (\\ d). / test (u)? 'opera opera' + RegExp. $ 1:
i ('konqueror')? w + 'konqueror': the
('chrome')? w + 'chrome':
i ('applewebkit /')? w + 'safari':
i ('mozilla /')? g:'',
, i ('mac')? 'mac ': i (' win ')?' win ':''
,' js'];
alert (u);
document.getElementsByTagName ('html') [0]. c.join className + = ('' )
})();
this feature is very light and runs instantly, gives elasticity to the css that should be the default.
I opinion, a further evolution of this method should be done by calculating effect on the server, the browser must be familiar with how to apply in advance and if the selectors on Sun is modified by a script, the renderizazione stops until it is the change and then css cascade must be recalculated, so you upload or before any css file or at the end of loading the document.
0 comments:
Post a Comment