在CSS和HTML中命名ID和类的最好方法是什么? [英] What's the best way to name IDs and classes in CSS and HTML?

查看:174
本文介绍了在CSS和HTML中命名ID和类的最好方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当为CSS命名类和ID时,使用什么是最好的方法。在这种情况下,我需要有一些命名约定,以便其他人可以拿起规则,并理解如何使用相同的模式命名自己的id和类。有什么建议么?我们创建的一些网站可能会变得相当复杂,但使用整体结构标题,内容和页脚。命名也必须有效。

When naming classes and IDs for CSS what is the best method to use. In this case I need there to be some kind of naming convention so that other people can pick up rules and understand how to name their own ids and classes using the same pattern. Any suggestions? Some of the sites we create can get pretty complex but use an overall structure header, content and footer. The naming must be efficient too.

我不是CSS的新手。我知道给他们的名字代表他们的结构等,但只是想知道人们的意见真的和方法这样做。

I am not new to CSS. I am aware of giving them names that represent their structure etc., but just want to know people opinions really and ways of doing this.

推荐答案

最好的建议是使用具有语义的类 b


好名字不会改变

考虑 >为什么 ,你想要的东西到
看起来一定的方式,而不是真的
关于 它应该看起来。看起来可以
总是改变,但是
的原因看起来保持不变。

Think about why you want something to look a certain way, and not really about how it should look. Looks can always change but the reasons for giving something a look stay the same.

好名字
警告重要可下载图像子菜单都是
好​​名字。它们描述了某个元素所代表的
,而它们
不可能改变。警告
将始终保持警告,没有
不管页面的外观
改变多少。

Good names warning, important, downloadableImage and submenu are all good names. They describe what a certain element represents, and they are not likely to change. A warning will always remain a warning, no matter how much the look of the page changes.

错误名称
border4px ,lighttext
prettybackground 都是错误的
名称的示例。你可以把边框换成
一个高达5个像素,或者背景
可能看起来很老了一会儿,而
根本不漂亮。
使用CSS的优点是,您不必为了更改您的网站的
外观而改变
。如果您必须
将所有浅色文本更改为深色文本,
,从而将所有类lighttext
更改为所有HTML页面中的darktext,
您可能会错过几个。

Bad names border4px, lighttext and prettybackground are all examples of bad names. You might fatten that border to a whopping 5 pixels, or the background may look pretty old after a while, and not pretty at all. An advantage of using CSS is that you won't have to change much in order to change the looks of your website. If you have to change all light text into dark text, and thus change all classes lighttext to darktext in all your HTML pages, you're likely to miss a few.

本文

这篇关于在CSS和HTML中命名ID和类的最好方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆