DEV Community

Jérôme Pott
Jérôme Pott

Posted on

11 6

Three neat CSS features

Here are three random CSS features that I didn't know about and was happy to learn that they exist.

1. caret-color

You can change the color of the blinking bar in input fields by simply using the caret-color property.

⚠ Support for the caret-color property is not so great:
caret-color support

2. nth-child(odd) & nth-child(even)

Those values are pretty well-known, but I only found out recently about them. They can come in handy, e.g. for alternating background colors in lists:

3. Gaps in Flexbox!

This is a truly awesome feature. In CSS grid, we can use the gap property to specify the gaps (gutters) between rows and columns. "Now" we get the same power with Flexbox!

However this feature is only supported by Firefox 63, which at the time of this writing hasn't been released to the wider public. I hope that the other vendors will implement it soon.

If you only see a big green block in the second example in the codepen above, it means that your browser does not support it.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (3)

Collapse
 
acz13 profile image
Albert Zhang • Edited

Personally I'm a bigger fan of parent child:nth-of-type(odd) rather than parent:nth-child(odd)... (e.g. tbody tr:nth-of-type(odd)) just in case you have some extra elements in there somewhere that aren't the list elements/table rows.

Collapse
 
bennypowers profile image
Benny Powers 🇮🇱🇨🇦

Very cool. I've often used margin-left for gaps in (row) flex containers before

.flex-row :not(:first-child) {
  /* specify a value or use auto to create a flexible spacer */
  margin-left: var(--flex-gap, auto)
}
Collapse
 
tplk profile image
Dmitry Teplov

It's probably better to set margin for all sides & negative margin on flex container so gaps are displayed correctly when flex children are wrapped to another row.
codepen.io/tplk/pen/wEZbxM

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay