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.

Edward - site -
Example is giving by the Gatan is understandable.

Jaydin - site -
You really are an amazing to come up with this kind of content.

important source - site -
Thanks for this awesome resource... I really appreciate all your hard work for this post!

Gage - site -
I heard lot of great reviews on your website that’s why I came here.

best nootropics - site -
Love this! Thanks for great resource. I got some new and useful ideas here..

como fazer o desfralde noturno - site -
I am glad you have started this blog, I am always looking for quality articles and your blog has it.

raising chickens - site -
Be thankful for you extremely considerably for this useful launch

protein powder reviews - site -
There are so much in this article that I would never have thought of on my own. Your content gives readers things to think about in an interesting way.

Donovan - site -
You did a great job on this writing. All of it was stunning.

Larry - site -
I have known your website from my friends. All of it was stunning.

bridesmaid presents - site -
I have read your article, it is very informative and helpful for me. I really admire the valuable information you offer in your articles.

online dance fitness class - site -
I found your blog using google search. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful info.

best testosterone booster 2017 - site -
Outstanding help as well as will not important have and acknowledging

Collin - site -
Your points of views were stunning I was just amazed with all of your thoughts.

sex supplements - site -
Look throughout how supplying the essential aspects of a recommend recognize out

Green Superfood Powder - site -
Outstanding as often! Really experienced it so obviously Jon for this certain focus

bridesmaid gift - site -
You will discover out a lot of techniques after going to your release

Happy New Year 2018 Greetings - site -
For this Happy New Year 2018 let us dream big and be annoyed with the simple blessings that activity has able us with. Let us accomplish boss affairs for the advancing approaching and plan acute to accomplish them. Let us not avoid the little blissful moments as they may accomplish up our day. Let us accomplish every moment memorable and aces of living. Let us bang alpha the New Year with a blithesome affection and bright apperception that will let us adjudge the appropriate affair to do. Let us airing appear the doors of arete this year.

Happy New Year 2018 Wallpapers - site -
New beginnings, beginning starts, reaffirmations of adulation and promises for a brighter approaching all appear to apperception as we ring in a New Year. There are the superficial, yet purposeful, promises we accomplish to ourselves. 2018 Best new year unique messages greeting cards wishes for your family friends and loved ones. We boldness to get in shape, lose weight, advance career paths, and the like. Then, there are the ardent promises we accomplish to others, whether aloud or in our minds. We wish to affliction more, accurate adulation more, about-face bad animosity in old relationships or seek out new admiring relationships. We try our actual best to put these desires into words. Though New Years can be a time of anniversary and cheer, there are abounding humans who are adverse difficult circumstances. They may be entering this time of year with alarm or anxiety. If that’s the case for anyone in your amphitheater of accompany or family, you can ability out and be an advance by adulatory them the best for the accessible year.

Miles - site -
You have given me so much idea in writing contents. Thanks

online dance workouts - site -
Awesome write-up. I have definitely experienced purchasing your blog site site content

best stomach fat burners - site -
I am feeling boosted after reading this post. Thanks for sharing it.

survival gear - site -
I recently found your blog and I find it extremely interesting.

Peyton - site -
I was totally amazed with the way you wrote this article.

Do Testosterone Supplements Work - site -
What an informative post - you have clearly done your research! Like you I have hundreds of pages bookmarked and it was great to add some new ones.

male enhancement pills - site -
Say many thanks to you so much for improving useful perspective of this problem issues

Fat Burners - site -
Thank you for sharing this insight, your post really helped me.. I really admired your kindness and hopefully you'll continue your goodness!

Thomas - site -
I was really excited with your next update. Kindly notify me for more updates.

Shakeology reviews - site -
Thank you so much for these amazing and fully comprehensive tips! I am happy to be here and I really inlove with your amazing website.

Aftercare Relapse Prevention Treatment Programme Auckland - site -
This is very educational content and written well for a change. It's nice to know that some people still understand how to write a quality blog post!

top 10 brain supplements - site -
I’m really impressed with your article, such great information you mentioned here, thanks for your sharing and waiting to see your future posts.

grilling planks - site -
Thank you so much! I stumbled across this post when searching but I sincerely appreciate all the tips and “behind the scenes” glimpses you’re providing. You have made this so cut and dry that I’d be a fool not to move forward with this.

Ryan - site -
I just thought. Could you please notify ne for more updates?

Gael - site -
By looking at your website I can surely say you have a great way of thinking.

unique bridesmaids gifts - site -
Incredible website! I wish you the best and wonderful of proper effects

Marcus - site -
You have given me so much knowledge in writing and choosing the right theme for my website.

testomax - site -
You webpage really helpful and useful for me

amazing grass - site -
This details truly magnificent to discuss to everyone

Graco Blossom 4-In-1 seating system - site -
The information in your blog so vibrant and love the way you write it. They both match really well on your blog post.

virectin reviews - site -
I would knowledgeable to thank you for the duties you have designed in scripting this papers

best stomach fat burners - site -
Very detailed guide and a valuable resource for newbie on this topic like me. I am looking forward to your next article on this topic! Thanks and have a nice day.

Brock - site -
I just love the relevance of your content on what's happening these days.

male enhancement supplements - site -
This webpage is big assist for me and this is a highly effective website

athletic greens - site -
I've absolutely qualified knowing this desired details these concerns

Male Enhancement Supplements - site -
Thank you for making it a 1-stop source. I have a lot of reading to do and I love it!

buy egg incubators - site -
Your blog site and created offered us with beneficial to carry out with

Performix SST - site -
This most vital functions is such a highly effective and awesome one

brain supplement reviews - site -
I totally agree with is stated on this post. These are pretty good thing to remember. Nice tips and great insights!

Aidan - site -
I was overly surprised with these thoughts you have written.

Complete Currency Trader Review - site -
This is also a surely extraordinary publish

ras al khaimah holiday deals - site -
Great post I must say and thank you for the priceless information. I really appreciate your post and look forward to more..

Mountain House foods - site -
Great work compiled by you in this site. Without an ounce of a doubt, this could be one of the excellent article I read in the web. Outstanding work you've done today and you deserve all the praise for it.

Andrew - site -

Your well-done content did amaze me. Please make this kind of content often.

Shakeology - site -
This is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!

bathmate reviews - site -
Extraordinary job! Keep up the higher submitting

buy chicken feeders - site -
Your website very inspiring ! Keep it up great perform

Do Testosterone Supplements Work - site -
Thank you for making it a 1-stop source. I have a lot of reading to do and I love it!

psychotherapy auckland - site -
A big thank you. I was desperately looking for this information and I’m glad that I found all the necessary stuff at one place. I should now take time to go through all of this...

Desmond - site -
This website did leave me stunned the way you made your contents was just spectacular.

protein powder reviews - site -
This was really clever blog. I’ve been following your site for a year and I could say your blog posts become better and better.

Male Enhancement Pills - site -
I found your article so good that I summarized it in my notes! I'm glad I found your amazing blog. Thanks!

pros and cons of It Works Greens - site -
Unbelievable website! I wish you the best and wonderful of good outcomes

Amazing Grass Green Superfood Reviews - site -
It’s just great to check out this kind of website, as what I have read on your contents all of it was really useful.

weight loss protein shakes - site -
This blog was absolutely fantastic. I am lucky to find a blog with something as well written as this.

Holden - site -
Your set of ideas in making content was really great, I hope you keep posting.

dubai five hotel - site -
I am totally agreed with you guys whatever you have explained here, it’s superb and amazing!

testogen review - site -
This was fantastic when it comes to info your webpage is the most valuable

MRE - site -
What a fabulous post this has been. Never seen this kind of useful blog before. I am grateful to you and expect more number of posts like these.

nootropic supplements - site -
I really like your post. And, I guess other visitors too are having fun while reading your blog.

Penelope - site -
Your ways of expressing opinion were really something. I am much amazed at how you have tackled such issues.

at home storage gold ira scams on the internet - site -
I am happy to get this helpful articles and view here

intercontinental abu dhabi beach - site -
This information you shared in this articles are impressive ideas

Fat Burners - site -
Pretty beneficial information here. I think this is really worth to save and definitely worth sharing post thanks!

front page - site -
Such great advice – love all of the articles you shared as well. Can’t wait to dig in!

wood grilling planks - site -
Thanks for providing this amazing article to us. I have been searching for blogs with this topic for a very long time and your post is exactly what I am looking for.

ras al khaimah holidays - site -
Very interesting post, as always. Years ago I found to-do lists massively helpful, so if you’re experience has been that this is far more useful, that’s very tempting.I’ll give this a try.

top 10 protein supplements - site -
It was a real good post very informative.

what does donald trump want to do with the economy - site -
This is a precious and wonderful blog site

Vega one protein reviews - site -
Incredible launch! I am actually preparing to across this details and things

shakeology - site -
Yes, I did share your website all of your contents were incredible.

Best Fat burners for women - site -
This is a truly good site post. Not too many people would actually. the way you just did. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best. with so much class.

Health Supplement Reviews - site -
I presume this column has cleared up that issue. I will spend money for Health Supplement Reviews next time. My step-brother used to tell to me why they gathered it was better to stay with Health Supplement Reviews.

Testosterone Boosters - site -
This is an awesome post. Thanks so much for pointing me in the right direction. Thanks again and really appreciated all of your help!

buy ultimate greens msm powder - site -
Thanks for the info. I do not know about them. Going forward this and I will use them. Thank you so much!

Mountain House foods - site -
This is a great article. Very unique and refreshing concept.

Angel - site -
I am very glad I got the chance to visit your website, please keep on inspiring.

ingredients shakeology - site -
Extraordinary important details and facts. I am truly happy with this site

Zion - site -
Your creativity was very impressive as always it gives me goosebumps.

top 10 fat burners - site -
Hands down the best guide for me God bless your heart. Thank you so much and more power.

causes of ulcerative colitis - site -
Useful post and extraordinary and impressive details and points here

fat burner pills - site -
Simple blog yet very fundamentals to keep in mind.

chicken nesting boxes - site -
A lot of amazing details from here I actually love this wonderful site you have

d bal - site -

Thank you for sharing this insight, your post really helped me.. I really admired your kindness and hopefully you'll continue your goodness!

nugenix testosterone booster - site -
This content did give me unending knowledge especially in writing contents.

amazing grass - site -
This was clearly the content that offers additional knowledge. Please keep me posted.

phenq fat burner review - site -
Fabulous article, it’s not often for me that I am intrigued to read every word of an article. Now I'm off following your site to see what else I can learn here.

Green Superfood Powder Reviews - site -
I was very impressed with how you had delivered such a subject. It was really great.

shakeology ingredients - site -
Outstanding strategy on this details thanks for sharing

bamp light - site -
I like the helpful info you supply in your articles. I will bookmark your weblog and test once more right here frequently. I am relatively sure I will learn many new stuff right right here! Best of luck for the next!

vigrx ingredients - site -
Extraordinary publish and spectacular assist thanks a lot

Fat Burners - site -
What a helpful blog post. You have done so much research, very impressive. I am really happy to hope to keep in touch with you..

testosterone booster reviews - site -
Spectacular site! Thanks for your important data it's been highly useful

Extenze Ingredients - site -
You have enlightened me by the words and wisdom you have shared. Cheers for this wonderful content.

how does performix SST Work - site -
What a fantastic post this is really big support to blog site

Kenneth - site -
It was just great to get the chance to visit your website please keep me posted for more updates.

fat burners men - site -
I got bunch and valuable information from your post. Many thanks for the effort.

shakeology powder - site -
Magnificent and relaxed at your details that you offer here

chicken coop waterers - site -
This ideas of your website are impressive and I really adore what you done here

where to buy testofuel - site -
I have enjoyed a lot while reading it, also a very thoughtful post..

Ajouter votre commentaire