css - 如何在 HTML 中的单独 div 中设置单独的链接样式

标签 css html hyperlink href

我在网页中有两个 div(比如 view_1 和 view_2)。我希望每个 div 中的链接样式都不同。假设链接的样式如下:

div view_1 中的链接样式:

a:link {
    color: #CB4C2F;
    text-decoration: none;
}
a:visited {
    color: #CB4C2F;
}
a:active,
a:hover {
    color: #B60A00;
}

div view_2 中的链接样式:

a:link {
    color: #B5B5B5;
    text-decoration: none;
}
a:visited {
    color: #808080;
}
a:active,
a:hover {
    color: #FFFFFF;
}

在页面中,我只想指定正在使用的 div。我不想为链接指定样式;链接应采用它们所在的 div 中的样式。如何实现?

最佳答案

将类添加到您的 div 中

查看_1

.view_1 a:link {
    color: #CB4C2F;
    text-decoration: none;
}
.view_1 a:visited {
    color: #CB4C2F;
}
.view_1 a:active,
.view_1 a:hover {
    color: #B60A00;
}

View _2

.view_2 a:link {
    color: #B5B5B5;
    text-decoration: none;
}
.view_2 a:visited {
    color: #808080;
}
.view_2 a:active,
.view_2 a:hover {
    color: #FFFFFF;
}

关于css - 如何在 HTML 中的单独 div 中设置单独的链接样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18128186/

相关文章:

html - 如何在固定元素后面将焦点元素带入 View

html - 告诉我黑白只是宽度和高度以及(最大/最小)宽度和高度的区别?

c# - 需要在常规超链接上执行隐藏代码

html - 为什么通过社交分享框会有一条线?

CSS:第一行上方的新行?

javascript - if条件不影响div的显示

javascript - 如何通过分配单个变量来减少此脚本中的链接数量

javascript - 无法读取 HTMLImageElement 处未定义的属性 'remove' - 切换内容

swift - 链接到多个网站

ssl - Opencart 链接不是 https?