简体   繁体   中英

CSS and filename coding conventions

What kind of convention do you (or your company) run on filenames and CSS class names? For example, let's say you have these class names: window, window top, window top left, window top right. How do you name those class names (and such filenames)?

Currently I am doing the following:

.window {
 background: url(images/window.png);
}

.window-top {
 background: url(images/window-top.png);
}

.window-top-left {
 background: url(images/window-top-left.png);
}

What other ways are there?

From the class names, I assume this is CSS for some sort of widget or plugin. The names you have given are pretty clear but to help avoid clashes I'd probably prefix them with a short plugin/widget specific string ie:

.mywindow-window{
}

.mywindow-window-top{
}

.mywindow-window-top-left{
}

These names are a little verbose, but should help make things clearer in the long run.

If I'm mistaken, then the naming convention you are hinting at should be fine - whats most important is that you are consistent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM