好的,所以我对在 css 中声明和调用一个类有点困惑。当我创建一个类时,它使用“。”但是当我调用它时它不会,例如。
.smaller-image {
width: 100px;
}
<a href="#"><img src="someimageurl.com" class="smaller-image" alt="some image
text."></a>
最佳答案
CSS 使用它们的 class
、id
或标签名称(例如 body
)将样式应用于 HTML 元素。
在编写应用于 类
的 CSS 规则时,您可以在类名前加上 .
前缀。
在编写应用于 id
的 CSS 规则时,您可以在 id 名称前加上 #
前缀。请注意,一个 id 只能由页面上的一个元素使用,而一个类可以随意使用。
例子:
div {} /* This is applied to all div elements */
.button {} /* This is applied to all elements with the `button` class */
#header {} /* This is applied to the element with the `header` id */
a.link {} /* This combines both the `a` tag and the `link` class */
关于CSS 调用和声明类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52681767/