DEV Community

Tommy Hodgins
Tommy Hodgins

Posted on

My CSS Wishlist


  • :previous to select the previous element sibling
  • :parent to select the parent element
  • :closest(selector) to select the closest ancestor matching a selector
  • :ancestor(selector) to select all ancestors matching a selector
  • [attribute < number] select if attribute is less than a number
  • [attribute > number] select if attribute is greater than a number
  • [attribute <= number] select if attribute is less or equal to a number
  • [attribute >= number] select is attribute is greater or equal to a number
  • :attribute(partial-name-*) select by partial attribute match
  • :tag(partial-name-*) select by partial tag name match


  • @element selector (condition) { stylesheet }


  • ew 1% of element's width
  • eh 1% of element's height
  • emin equal to min(1ew, 1eh)
  • emax equal to max(1ew, 1eh)


  • auto-expand as a value for width and height properties
  • offsetWidth, offsetHeight, offsetLeft, offsetTop
  • scrollWidth, scrollHeight, scrollTop, scrollLeft
  • innerHTML.length, value.length
  • cursor X position, cursor Y position


  • aspect-ratio to set height based on the element's width and a ratio


  • clamp(min, mid, max) to limit scalable values with a minimum and maximum
  • round(number) gives the nearest integer to a given number
  • floor(number) gives the largest integer equal or less than a given number

Top comments (2)

ssalka profile image
Steven Salka

I'm still waiting on the :has selector - if it ever reaches maturity, I'd be using it all over the place

tomhodgins profile image
Tommy Hodgins

It's been in the spec for 4 years, but no browsers have found a way to implement it in an efficient enough way, so until then we have to use JavaScript. I see this:has(that) as something like Array.from(document.querySelectorAll(this)).filter(tag => tag.querySelector(that)), so to make that a little more useful I would write a helper function like this:

I'm using a little plugin to read JS-in-CSS so I can write it from my stylesheet, here's a little more about how that's working, but as long as you could run this helper function on the right events it would mark up elements in the DOM that match our :has() rule and give them unique attributes. Then the function returns a string which is text of a CSS stylesheet, with the rules written targeting the elements with our new unique attributes. As long as you can populate a stylesheet in DOM or CSSOM with the CSS that the function returns it will work: