区分名称和href [英] Differentiate between a name and a href
问题描述
在CSS中,我想为
<a name="tag">one font and color</a>
和
<a href="link">a different font and color</a>
但是,设置 标签的属性会使两段文本具有相同的颜色.我怎样才能让它们与众不同?我必须在每一个上都放一个
id
吗?
However, setting the attributes for the <a>
tag make both pieces of text have the same color. How can I make them different? Do I have to put an id
on every single one?
推荐答案
我不明白为什么你会有一个锚标签,而没有 href
.
I'm confused as to why you would have an anchor tag, without an href
.
name
属性的用途是用于表单,以便在提交表单时可以检索数据.
The purpose of the name
attribute, is for forms, so that when you submit a form, you can retrieve the data.
为了设置 HTML 元素的样式,您需要使用 id
或 class
.一个 class
可以在一个页面上多次使用,其中一个 id
在一个页面上只能使用一次.
In order to style HTML elements, you'll want to use either an id
or a class
. A class
can be used multiple times on a page, where an id
can only be used once per page.
绝对可以根据属性设置锚标记的样式,如下所示:
It's absolutely possible to style an anchor tag based on the attribute like so:
a[name] {
/* Style 1 */
}
a[name="tag"] {
/* Style 2 */
}
a[href] {
/* Style 3 */
}
a[href="link"] {
/* Style 4 */
}
但最好使用 id
和 class
.
这篇关于区分名称和href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!