CSS助记符:你如何记住#或.是用于班级还是ID?
#test
是 id="test"
的选择器
.test
是 class="test"
的选择器
但是你如何记住它们的方向(例如不是.=id)
#test
is the selector for id="test"
.test
is the selector for class="test"
but how do you remember which way round they are (eg not .=id)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
好吧,事实上,这些事情是如此常见,以至于大多数人不需要助记符来记住它们,但我想出了一些东西,如果它有帮助的话:
就文件名而言,a
.
,然后是扩展名表示事物的类型。这种类型可以有很多不同的东西。通过 CSS,使用类,您可以为相同类型的许多元素表示单一样式。就 URL 而言,
#
表示指向文档中特定位置的锚链接。它仅指一个位置。通过 CSS,您可以使用 ID 来表示单个特定元素的单个样式。Well, in truth these things are so common that most people don't need mnemonics to remember them, but here's something I came up with, if it helps:
In terms of a filename a
.
and then an extension denotes a type of thing. There can be many different things of this type. With CSS, using classes you can denote a single style for many elements of the same type.In terms of a URL, a
#
denotes an anchor link to a specific spot in the document. It refers to one location only. With CSS, using IDs you denote a single style for a single specific element.如果警察发现您有“哈希”行为,他会要求查看您的身份证件。如果不是,你就可以保持优雅。这确实很愚蠢,但我就是这样记住的。
If a police officer catches you with "hash," he will ask to see your ID. If not you get to stay classy. It's really dumb, but that's how I remember.
(PS:那些“你学得和我不一样,所以你很糟糕”的评论是怎么回事?天啊。重复对我来说没问题,但如果我能想象一些东西,我就能更快地掌握东西。事实上,越奇怪的东西越容易记住!)
(P.S.: What's with all the "you learn differently than me, so you suck" comments? Goodness. Repetition is OK for me, but if I can visualize something I pick things up more quickly. In fact, the weirder something is the easier it is to memorize!)
我学习它的方式与我学习引号(而不是括号)用于属性值的方式相同 - 通过输入几次。
但是,如果您或您认识的人被
#
与.
绊倒,请考虑许多编程语言使用.
来访问类类型的对象。I learned it the same way I learned that quotes (rather than parentheses) are used for attributes' values — by typing them a couple of times.
If you or someone you know gets tripped up by
#
vs.
, though, consider that many programming languages use a.
to access the members of an class-typed object.我发现我迟到了一天(可能还差一美元),但我在早期也遇到了同样的问题,以下内容有所帮助:
对于作为 Class 选择器的点 (.),我记得它是:“我的课程总是从点开始,不会早一分钟或晚一分钟。”
对于ID的数字符号(#),我只是提醒自己,没有号码的身份证(entification)卡是不完整的。
I see I'm a day late (and maybe a dollar short), but I had the same problem in the early days and the following helped:
for the dot (.) as the selector for Class, I remembered it as: "My class always starts on the dot, not a minute early or late."
for the number sign (#) for ID, I just reminded myself that an ID(entification) card is incomplete without its number.
花大量时间编写 CSS。当你犯错的次数足够多时,你的大脑就会屈服并保留它。
Spend lots of time writing CSS. When you've got it wrong enough times, your brain will give in and retain it.