re: Share your CSS knowledge VIEW POST


Several tricks that I used very often:

Select all the elements with same class except for the first one

While you complaining there's no :not(:first-of-class) selector, you can do this instead:

.foo + .foo {
  margin-top: 1rem;

Mimicking grid-gap without using grid layout:

.album {
  --gap: 1rem;
  padding-top: var(--gap);
  padding-left: var(--gap);

.album > .photo {
  margin-right: var(--gap);
  margin-bottom: var(--gap);

Clear all the predefined styles

a {
  display: block;
  text-decoration: none;
  /* blah blah blah... */

a.logo {
  /* This disables all the rules defined above */
  all: unset;
  /* start from fresh */

I never knew about all! Thank you for this!

code of conduct - report abuse