fastclemmy.com

Vite fait bien fait

# 10-12-2003

Maintenant que vous êtes sûr que votre site est complètement valide, il est peut-être temps de remettre le nez dans le code pour l'optimiser un peu. Voici quelques conseils pour faire le ménage de printemps (puisque *hum* c'est la saison) dans votre HTML et votre CSS.

A réserver aux codeurs avertis bien sûr.

Raccourcis déclaratifs

Il existe plusieurs moyens de déclarer une couleur dans un fichier CSS. Prenons par exemple la couleur blanche : white, #ffffff et #fff sont équivalents. La dernière façon de procéder révèle qu'on peut économiser des doublons hexadécimaux en mettant une seule fois la valeur, de même la couleur rouge sang #ff0000 pourra s'écrire #f00.

Les propriétés d'arrière-plan peuvent également bénéficier d'une cure d'amaigrissement :

p {background-image:url(../images/fond.gif); background-color:#ccc; background-position:50% 50%; background-repeat : no-repeat; background-attachment: fixed; }

devient ainsi

p {background: url(images/fond.gif) #ccc 50% no-repeat fixed }

Idem pour les bordures, les marges et le padding :

margin: 8px 2px 1px 4px;

Cette ligne de CSS fixe l'épaisseur des marges dans le sens des aiguilles d'une montre (haut, droite, bas, gauche).

Le regroupement de propriétés

Au fur et à mesure de l'écriture de votre fichier CSS, vous allez rapidement avoir des propriétés en commun. A la fin du projet il est temps d'y rejeter un oeil et d'optimiser le tout. Comment faire ? C'est très simple :

div#menu { margin-left:5px; background-color:#ccc; } div.onglet { background-color:#ccc; } div#menuVertical { background-color:#ccc; padding-right:3em; border-top:1px solid black; }

devient ainsi

div.onglet, div#menu, div#menuVertical { background-color:#ccc; } div#menu { margin-left:5px; } div#menuVertical { padding-right:3em; border-top:1px solid black; }

On déclare les propriétés communes aux différents styles, puis on déclare ce qui les différencie.

Optimisation HTML : les bienfaits du ciblage CSS

Quand on débute en XHTML/CSS, on a tendance à user et abuser des <div> et autres <span> pour pouvoir les styler dans son fichier CSS. Par exemple, on peut écrire pour un en-tête de site :

<div id="enTete"><h1>Mon titre de site</h1></div>

En fait, ici le <div> n'a aucune valeur ajoutée, aucun sens. On peut donc le supprimer sans regret et cibler le texte "Mon titre de site" en stylant le <h1> dans le fichier CSS. L'exemple est trivial, mais cette philosophie d'ensemble s'applique à de nombreux cas.

Pour en savoir plus, consultez les liens suivants :
Introduction to CSS shorthand properties
CSS Shorthands, part I
Writing efficient CSS

#xhtmlCSS

Vos commentaires

be-rewt - site -
Et tant qu'on y est, on peut supprimer les ";" qui suivent toutes les dernières propriétés d'un bloc (encore que là, c'est vraiment un truc de rapiat pour sauver quelques malheureux octets).

selarips -
/ à supprimer après correction, je suis pas là pour foutre la zone non plus
je dis pas ça pour jouer au con mais cette news ne valide pas

fastclemmy - site -
Merci selarips, c'est corrigé. En fait le problème n'était pas spécifique à ce log, mais à tous. Cleanage de code = validation qui roule.

Moi qui ne validais que la page d'accueil après avoir rédigé chacun de mes logs, me voilà bien pris !

Anubis - site -
Concernant ton dernier point, j'ajouterais qu'un bon découpage de la page avec des permet souvent de séparer suffisament les contextes pour ne plus avoir besoins de classes.

Gatan - site -
Je me permet d’ajouter un type de sélecteur qui peut se révéler très pratique c’est "*".
Ce sélecteur permet de sélectionnez l’ensemble des éléments d’un conteneur.
Exemple :
body * {border: 1px red solid;}
permet d’aficher une bordure rouge à l’ensemble des éléments de "body".
* div {border: 1px red solid;}
permet d’afficher une bordure rouge sur l'ensemble des éléments "div" appartenant au document.

Gatan - site -
Je viens de me pencher sur les sélecteurs par attributs voici donc deux lignes à ajouter à vos pages pour un débuggage les doigts dans le nez :

*[id]:before {
content:"ID:"attr(id)"";
color: white;
font-size: 0.8em;
padding: 0.1em;
background: red;
}
*[class]:before {
content:"class:"attr(class)"";
color: white;
font-size: 0.8em;
padding: 0.2em;
background: red;
}
Ces deux styles permettent (dans un navigateur avancé, genre Firebird), d’afficher les noms de "class" et d’"id" pour chaque élément de la page.

JMF - site -
Gatan, il est plus simple dans ce cas d'utiliser l'extension pour Mozilla et FireBird WebDevelopper. (http://chrispederick.myacen.com/work/firebird/webdeveloper/)

En plus de faire cela elle a bien d'autres fonctions indispensables pour le développeur Web.

Gatan - site -
Aussi…JMF
Mais c'était surtout pour montrer par l’exemple la puissance de ce mode de sélection.

gizmo - site -
Ganta, dans le deuxième exemple de ton premier post, le * est inutile.

gatan - site -
Exact.

sparxx rx review - site -
Male enhancement pills are also created to resolve the little penis. Researchers, doctors, as well as nutritional experts been employed by together in order to invent the very best effective male enhancement pill. We.

Amazon Bontonwear - site -
I appreciate your writing style! This could be an incredible assistance for the dynamic learning and growth. Excellent working!

philcharls - site -
All well-written and clear

dvr without subscription fees - site -
I came onto your blog while focusing just slightly submits. Nice strategy for next, I will be bookmarking at once seize your complete rises

sandalye - site -
Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me.

aftermarket wheels - site -
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.

Black Friday Mattress Sale 2015 - site -
Hi there, I found your blog via Google while searching for such kinda informative post and your post looks very interesting for me.

best deals on beds - site -
I read this article. I think You put a lot of effort to create this article. I appreciate your work.

black friday mattress deals - site -
I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

black friday mattress deals - site -
I read this article. I think You put a lot of effort to create this article. I appreciate your work.

black friday 2015 - site -
I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job!

Black Friday sales on adjustable beds - site -
Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here.

black friday 2015 mattress deals - site -
Mmm.. good to be here in your article or post, whatever, I think I should also work hard for my own website like I see some good and updated working in your site.

online mattress retailers - site -
Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here.

black friday bed deals - site -
wow this good but ,I like your post and good pics may be any peoples not like because defrent mind all poeple ,

walmart black friday - site -
I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job!

dance mat typing level 2 stage 3 - site -
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.

breast cancer test cost - site -
You have done a great job. I will definitely dig it and personally recommend to my friends. I am confident they will be benefited from this site.

facebook modules pespro latest - site -
his is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.

compare memory foam mattresses - site -
I read this article. I think You put a lot of effort to create this article. I appreciate your work.

new mattress smell - site -
Yes, great US Military force. Also, in his post you have given a chance to listen about US Military. I really appreciate your work. Thanks for sharing it.

錢莊借款 - site -
Took me time to read all the comments, but I really enjoyed the article. It proved to be Very helpful to me and I am sure to all the commenters here! It’s always nice when you can not only be informed, but also entertained!

mattress types. - site -
Easily, the article is actually the best topic on this registry related issue. I fit in with your conclusions and will eagerly look forward to your next updates. Just saying thanks will not just be sufficient, for the fantasti c lucidity in your writing. I will instantly grab your rss feed to stay informed of any updates.

Industrial Supply - site -
This is a great motivating content.I am fairly much happy with your great work.You put really very details. Keep it up.

gold company ratings - site -
Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

white label seo reseller - site -
Your post was very nicely written. I’ll be back in the future for sure!

hair coloring downtown NYC - site -
I was very pleased to find this site.I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.

salt pepper grinder - site -
I was very impressed by this post, this site has always been pleasant news Thank you very much for such an interesting post, and I meet them more often then I visited this site.

Obat Gagal Ginjal Tanpa Cuci Darah - site -
Sehabis membelinya, saya minum sebanyak tiga puluh ml, tiga kali per hari, ditambahkan teh Murbei, 1 kali setiap bangun tidur pagi dengan takaran lebih kental. Cukup dengan tempo 10 hari bengkak pada badan sudah kempes, sakitnya juga sembuh.

Obat Kanker Darah Stadium 4 - site -
Leukemia salah satu penyakit yang amat berbahaya. Pengidap penyakit kanker darah harus segera ditangani oleh para medis. Sebab jika tidak, penderita pasti tak tertolong.
Kanker darah dapat membunuh penderitanya hanya dalam hitungan pekan atau bahkan hanya dalam beberapa hari.

Obat Batu Ginjal Alami Tanpa Operasi - site -
Obat Alami Penyakit Batu Ginjal Terbaik Amazon Plus Penjelasan Tentang mengenai Obat Herbal Batu Ginjal Amazon Plus, Pengobatan alami yang bisa dipercaya adalah menggunakan obat herbal batu ginjal .

Satta Matka - site -
Amazing Satta Matka Site For You

TestoFuel Review - site -
This is very awesome blog. I am happy to have the opportunity to visit here. Thanks and best of luck to you!

dance lessons long island - site -
Thanks for sharing this brilliant post. Your article is on of the best I have ever read.

cardio dance - site -
Your blog site presented us with valuable vital data and information to work with

plank fish - site -
This is my first time to visit your site and after going through few posts I have to be a regular visitor.

PhenQ - site -
I share your blog with on my social media page constantly. I look forward to getting it! Thank you for the wonderful read and please kindly post more..

applied kinesiology - site -
Magnificent write-up! I can't get up to preparing more from you incredible info right here

surf t shirts - site -
It is very uncommon nowadays, lots of sites and blogs having copy pasted or rewritten info. But here, no doubt, info is original and very well structured. Keep it up.

mens t-shirts - site -
Thank you for posting this amazing article! It’s fantastic to read such a helpful article about this topic.

Bryce - site -
I am very thankful I had the chance to visit your website.

fat burner pills - site -
Great post and really helpful. I will read this article more often..

male enhancement supplements - site -
Your content was truly a aspect, I really liked all the facts you have released

Ajouter votre commentaire