Созонов Алексей

Веб-разработчик

Убрать margin для первого или последнего элемента

09.08.2015

1 способ

Просто добавьте класс .first или .last

.first { margin-top: 0 !important; margin-left: 0 !important; }
.last { margin-bottom: 0 !important; margin-right: 0 !important; }

2 способ

Использовать псевдо-селектор

* > :first-child { margin-top: 0 !important; margin-left: 0 !important; }
* > :last-child { margin-bottom: 0 !important; margin-right: 0 !important; }

3 способ (каждый 3-ий элемент)

Если у вас сетка из div-ов, то можно сделать так

* > :nth-child(3n+3) { margin-right: 0; }

4 способ (чтобы точно работало)

$("* > :nth-child(3n+3)").css("margin-right", 0);
#CSS‏‎