html - 更改导航栏中所选元素的字体颜色

标签 html css

我正在尝试使用 css 中的已访问函数更改导航栏中所选元素的字体,但它不适用于我的应用程序。我可以使用其他解决方案吗?这是我当前的脚本:

 <style>
    .navbar-header:visited {
        color: red;
    }
</style>


 <html>
 <body>

 <div class="navbar">
    <div class="container" style="border-style: groove;">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            @Html.ActionLink("Home", "Main", "Home", new { area = "" }, new { @class = "navbar-brand", style = "color: #8C8D8E;" })
            @Html.ActionLink("Name List", "Name", "Home", new { area = "" }, new { @class = "navbar-brand", style = "color: #8C8D8E;" })
            @Html.ActionLink("Details", "Details", "Home", new { area = "" }, new { @class = "navbar-brand", style = "color: #8C8D8E;" }     
        </div>
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav"></ul>
        </div>
    </div>
</div>

 </html>
 </body>

任何建议/评论TIA

最佳答案

您尝试使用的特定样式不应该用在您的 header 上,而应该用在 header 中包含的 anchor 标记上。

因此,你只需要做一个小改动:

.navbar-header a:visited {
        color: red;
    }

这是因为你的DIV没有href,所以访问不了或者访问不了。它是控制页面重定向的 anchor 标记。

此外,因为您创建了您的操作链接,然后将内联样式放入其中,所以它优先于 CSS external links.

您必须从 Action 创建中删除样式,您可以通过将相同的样式放在类中来解决您的问题。

@Html.ActionLink("Home", "Main", "Home", new { area = "" }, new { @class = "navbar-brand" })

在上面,您可以看到我已经删除了样式作为示例。然后您只需添加以下 CSS。

.navbar-brand {
        color: #8C8D8E;
    }

关于html - 更改导航栏中所选元素的字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53586541/

相关文章:

html - 将 css 应用于具有相同模式的元素

html - 导入的 svg 作为 img 不起作用

css - 使用 CSS 样式表(背景图像属性)在同一行 float 2 个图像

html - 在 iframe 中打开链接时如何更改菜单链接颜色?

javascript - CSS 文件导致 react/webpack 配置出错

html - CSS:为什么我的 HTML 元素以某种方式相对定位?

html - 将自定义设计添加到 ActiveAdmin - rails

javascript - slideToggle 动画 "show"但不是 "hide"

html - 在perl中刷新没有 "Confirm Form Resubmission"的浏览器

asp.net - Internet Explorer 呈现问题