Selecting a nested element with :nth-child

后端 未结 2 1015
你的背包
你的背包 2021-01-22 23:02

I\'m having problems targeting nested elements with the :nth-child() selector. How can I target the second and third .service?

2条回答
  •  星月不相逢
    2021-01-22 23:40

    If you want to target anything other than the first element, use :not, like so:

    div {
      display: inline-block;
      background: black;
      color: white;
      height: 100px;
      width: 100px;
      float: left;
      text-align:center;
      line-height:100px;
    }
    div:not(:first-child) {
      border-left: 2px solid red;
    }
    One
    Two
    Three

提交回复
热议问题