简体   繁体   English

尝试针对特定链接在 CSS 中进行样式设置

[英]Trying to target specific links for styling in CSS

I'm trying to target just the links in my nav bar as I have inserted other dummy links further down in my home page that I want to style on their own.我试图只定位导航栏中的链接,因为我在主页的下方插入了其他我想自己设置样式的虚拟链接。 I have tried adding an ID/class to the section that my header tags live in, and I have also tried targeting each individual with a class or ID attribute.我尝试将 ID/类添加到我的标题标签所在的部分,并且我还尝试使用类或 ID 属性来定位每个人。 This is lending itself to some functions being applied while others are not.这有助于某些功能正在应用,而其他功能则没有。 This is purely a little practice site I am building alongside what I learn in my Udemy course, but I wanted real-time feedback.这纯粹是一个小练习网站,我正在与我在 Udemy 课程中学习的内容一起构建,但我想要实时反馈。 Here is the HTML I have right now:这是我现在拥有的 HTML:

<header id="nav-bar">
  <h1 class="welcome">Welcome to Peter's Penguins!</h1>

  <nav class="nav">
    <a href="index.html" class="nav-links">Home</a>
    <a href="about.html" class="nav-links">About Us</a>
    <a href="team.html" class="nav-links">Meet The Team</a>
    <a href="contact.html" class="nav-links">Contact Us</a>
    <a href="penguins.html" class="nav-links">Our Penguins</a>
  </nav>
</header>

and my (external) CSS is:我的(外部)CSS是:

    .nav {
      font-family: sans-serif;
      font-weight: bold;
      text-decoration: none;
    }

    .nav-links {
      text-decoration: none;
      padding: 5px;
      margin: 23px;
    }

Is there a way I can use the pseudo-class property for my LVHA portions?有没有办法可以将伪类属性用于我的 LVHA 部分? Ie IE

    .nav-links a:link {

    }


    .nav-links a:visited {

    } 

Or is this improper syntax?或者这是不正确的语法?

You can do something like你可以做类似的事情

a.nav-links: visited {

}

This will target more specific (higher priority).这将针对更具体(更高优先级)。

.nav .nav-links {
  color: blue;
}

Beloow wil give it a little bit more priority because it is more specific.下面将给予它更多的优先级,因为它更具体。

ul.nav a.nav-links {
  color: blue;
}

And you may use the :hover, :active, and other for functionality您可以使用 :hover、:active 和其他功能

.nav .nav-links:hover,
.nav .nav-links:active {
  color: red;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM