reskwer
@reskwer
front-end developer

Почему не работает второй :last-child?

Есть вот такой html
<section class="contact">
		<h3>Contact Us</h3>
		<h2>Work With Us</h2>
		<img src="img/map.png" alt="">
		<div>
			<h3>location</h3>
			<span class="address">198 West 21th Street, New York, NY 10010</span>
			<h3>Fax</h3>
			<span class="phone">+88 (0) 202 0000 000</span>
			<span class="phone">+88 (0) 202 0000 000</span>
		</div>
		<div>
			<h3>phone</h3>
			<span class="phone">+88 (0) 101 0000 000</span>
			<span class="phone">+88 (0) 101 0000 000</span>
			<h3>email</h3>
			<span>elegant@elegant.com</span>
			<span>commercial@elegant.com</span>
		</div>
	</section>


И вот такой вот Sass (SCSS)
.contact{
    div{
      .phone{
        min-width: 70%;
        display: inline-block;
      }
      &:nth-of-type(1) h3:nth-of-type(2){
        color: #000;
        margin: 87px 0 0 0;
      }
      &:nth-of-type(1) .phone{
        margin-top: 38px;
      }
      &:nth-of-type(1) .phone:last-child{
        margin-top: 8px;
      }
      &:nth-of-type(2) .phone{
        margin-top: 38px;
      }
      &:nth-of-type(2) .phone:last-child{
        margin-top: 8px;
      }
    }
}


И вроде все нормально работает, за исключение последнего правила
&:nth-of-type(2) .phone:last-child{
        margin-top: 8px;
      }

Почему это работает.
&:nth-of-type(1) .phone:last-child{
        margin-top: 8px;
      }

а вот это строкой ниже уже нет
&:nth-of-type(2) .phone:last-child{
        margin-top: 8px;
      }
  • Вопрос задан
  • 193 просмотра
Решения вопроса 2
@MNB
потому что он не last-child. После него есть элементы.
Ответ написан
Комментировать
e_s_l
@e_s_l
Full-stack web developer
.phone в последнем блоке не является :last-child (не является последним дочерним) - поэтому и не срабатывает
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
webinar
@webinar
Учим yii: https://youtu.be/-WRMlGHLgRg
.phone:last-child - это последний детеныш внутри .phone, а у Вас таких нет
Тут видимо надо .phone:last-of-type
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы