Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is using class names like 'right' considered bad practice?

If I have class names such as "left", "right", "clear" and xhtml like

<a href="index.php" class="right continueLink">Continue</a>

With CSS like

.right {
float: right;
}

I know it's not a semantic name, but it does make things much easier sometimes.

Anyway, what are your thoughts?

like image 924
alex Avatar asked Nov 28 '22 16:11

alex


2 Answers

I don't think that's a very good idea. Now when you (or a future maintainer) go to change your website layout, you'll either have to change .right to {float:left;} (obviously a bad idea) or go through all your HTML files and change right to left.

Why do you want that particular link to be floated right, and the other .continueLink's not to? Use the answer to that question to choose a more descriptive class name for that link.

like image 93
Paige Ruten Avatar answered Dec 04 '22 06:12

Paige Ruten


css is about presentation of the structure of your html page.

Meaning its classes should represent the structure of the document ('article', 'extra-links', 'glossary', 'introduction', 'conclusion', ...).

You should avoid any class linked to a physical representation ('left', 'right', 'footnotes', 'sidenotes', ...), because, as the Zen Garden so clearly illustrates, you can decide to place any div in very different and various ways.

like image 37
VonC Avatar answered Dec 04 '22 06:12

VonC