简体   繁体   English

除了a:第一个孩子还是aside:第一个孩子a?

[英]aside a:first-child or aside:first-child a?

I'm creating a sidebar and I need do remove text decoration by using the first-child and I don't know what is the right way to approach it, this is a sample of the html code: 我正在创建侧边栏,我需要使用第一个孩子删除文本修饰,但我不知道正确的处理方法是什么,这是html代码的示例:

<aside>
    <nav>
         <div id="guide-item" class="content"> <a href="#">Início</a> </div>
         <div class="horizontalLine"></div>
         <div id="guide-item" class="content"> <a href="#">Notícias</a> </div>
         <div id="guide-item" class="content"> <a href="#">Vídeos</a> </div>
         <div class="horizontalLine"></div>
     </nav>
</aside>

The effect is something similar to Google+ navigation bar. 效果类似于Google+导航栏。 This is a sample of the css code: 这是css代码的示例:

/* Left Sidebar */

aside {
    float: left; position: fixed;
    margin-top: 50px;
    background: #ffffff;
    height: 100%; width: 230px;
    box-shadow: 0 0 55px rgba(0, 0, 0, 0.06);                   /* Inner shadow, rgba values can not be separated from his parent. The last value is a alpha parameter. */
    z-index: 1;
}


aside a:first-child {                                          /* Main navigation links (aside nav a {}). This way you can have 2 different styles inside the nav element. */
    text-decoration: none;                                      /* O first-child deixou de funcionar quando troquei a ordem no html  mas aside a:first-child e nth:child já funcionam. */
    color: inherit;
}


#guide-item.content {                                           /* Ao ter a div antes da classe posso reaproveitar a classe e criar algo mais dinamico. */
    padding: 13px 22px;
}

.content:hover {                                                /* Ao substituir a div pela classe passo a deixar de precisar de criar mais divs para o mesmo efeito. */
    background: #f5f5f5;
}

.horizontalLine {                                               /* Linha horizontal estilizada para substituir a tag tradicional, <hr>. */
    border-bottom: 1px solid #e5e5e5;
}

Please bare in mind that I'm new in programming and I'm a teenager. 请记住,我是编程新手,而且我还是青少年。 Thank you for taking your time reading this. 感谢您抽出宝贵的时间阅读本文。

Try this: 尝试这个:

aside nav div:first-child a {
  text-decoration: none;
  color: inherit;
}

Here is the DEMO 这是演示

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

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