代码之家  ›  专栏  ›  技术社区  ›  Clément

我不能把盒子放进盒子里,而且颜色不变

  •  0
  • Clément  · 技术社区  · 7 年前

    在我的网站主页上有4个超链接,我想以同样的方式出现在每个页面上。除了我希望我所在页面的链接与我将鼠标放在上面时的颜色相同。

    我想我可以用这个代码得到:

    .navigation {
      padding: 40px 0px;
      position: relative;
      text-align: center;
      width: 100%;
      font-size: 30px;
    }
    
    .navigation a {
      background: black;
      border: 1px solid grey;
      border-radius: 7px;
      color: white;
      display: inline-block;
      margin: 100px 35px;
      padding: 14px;
      text-decoration: none;
      opacity: 0.75;
      font-family: impact;
    }
    
    .navigation a:hover {
      background: white;
      border: 1px solid black;
      color: black;
    }
    
    #contact {
      background: white !important;
      color: black !important;
    }
    <div class="navigation">
      <a href="./productions.html">Mes productions</a>
      <a href="./DJ.html">DJ</a>
      <a target="_blank" href="./CV.pdf">Mon CV</a>
      <div id="contact">
        <a href="./contact.html">Me contacter</a>
      </div>
    </div>

    1 回复  |  直到 7 年前
        1
  •  1
  •   Nuchimik    7 年前

    但我认为在这种情况下,将链接放在“div”中是一种不好的做法。您可以简单地为链接注册一个类,并为此类编写样式。

    .navigation {
      padding: 40px 0px;
      position: relative;
      text-align: center;
      width: 100%;
      font-size: 30px;
    }
    
    .navigation a {
      background: black;
      border: 1px solid grey;
      border-radius: 7px;
      color: white;
      display: inline-block;
      margin: 100px 35px;
      padding: 14px;
      text-decoration: none;
      opacity: 0.75;
      font-family: impact;
    }
    
    .navigation a:hover {
      background: white;
      border: 1px solid black;
      color: black;
    }
    
    #contact a {
      background: white !important;
      color: black !important;
    }
    <div class="navigation">
      <a href="./productions.html">Mes productions</a>
      <a href="./DJ.html">DJ</a>
      <a target="_blank" href="./CV.pdf">Mon CV</a>
      <div id="contact">
        <a href="./contact.html">Me contacter</a>
      </div>
    </div>