@Ivanushka255

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

https://codepen.io/Van245/pen/abdrYRV

Мне надо для третьего блока отменить margin-right. Прописываю через last-child – не работает. Что не так?

<div class="third_block">
		<div class="wrap_third_block">
			<div class="one_block bl">
				<h2 class="third_h">camping</h2>
				<p class="third_p">Lorem ipsum dolor sit amet, consectetur adip</p>
			</div>
			<div class="two_block bl">
				<h2 class="third_h">hiking</h2>
				<p class="third_p">Lorem ipsum dolor sit amet, consectetur adip</p>
			</div>
			<div class="three_block bl">
				<h2 class="third_h">scuba diving</h2>
				<p class="third_p">Lorem ipsum dolor sit amet, consectetur adip</p>


.wrap_third_block {
	display: flex;
}

.third_h {
	color: #ffffff;
	font-family: Roboto;
	font-size: 24px;
	font-weight: 500;
	text-transform: uppercase;
}

.third_p {
	color: #ffffff;
	font-family: Roboto;
	font-size: 12px;
	font-weight: 300;
}

.bl {
	width: 360px;
	height: 240px;
	border-radius: 10px;
	background-color: #cc5c33;
	margin-right: 30px;
}

.wrap_third_block:last-child {
	margin: 0;
}
  • Вопрос задан
  • 140 просмотров
Решения вопроса 2
Seasle
@Seasle Куратор тега CSS
Raxen
@Raxen
Lead Frontend Developer, Beeline
Ваш псевдоселектор направлен не на потомков класса, а к контейнеру с классами, вы пытаетесь взять последний элемент с классом .wrap_third_block а он у вас всего один и да, к нему добавляется margin-right: 0;

Если вы хотите взять последний элемент из трех, то
.bl:last-child {
  margin-right: 0;
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

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