This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-09-14
Channels
- # announcements (1)
- # beginners (85)
- # calva (23)
- # cider (3)
- # clj-kondo (33)
- # cljs-dev (12)
- # clojure (79)
- # clojure-dev (5)
- # clojure-europe (1)
- # clojure-nl (3)
- # clojure-uk (3)
- # clojurescript (5)
- # clojutre (2)
- # data-science (30)
- # datomic (3)
- # duct (7)
- # fulcro (8)
- # garden (18)
- # jackdaw (2)
- # leiningen (1)
- # off-topic (3)
- # pathom (4)
- # qa (24)
- # re-frame (13)
- # reagent (3)
- # shadow-cljs (58)
- # testing (1)
Hi there, if I start out with something like
(ns some-file.css
(:refer-clojure :exclude [> not])
(:require
[garden.selectors :as g :refer [& first-child > not ]]))
[:div.incomplete-actions {:margin-bottom "-1.5rem"}]
how can I get to
div.incomplete-actions {
margin-bottom: -1.5rem;
}
div.incomplete-actions > div.incomplete-action:not(:last-child) {
margin-bottom: 0;
}
(require '[garden.core :as css])
(require '[garden.selectors :as $])
(css/css
[($/> ($/div :.incomplete-actions)
($/div :.incomplete-action ($/not $/last-child)))
{:margin-bottom 0}])
;; =>
;; div.incomplete-actions > div.incomplete-action:not(:last-child) {
;; margin-bottom: 0;
;; }
That's very nice, thank you @noprompt! I was trying to use [:div...
in combination with those. Would you say the selectors are more powerful?
(def $last-incomplete-action
($/> ($/div :.incomplete-actions)
($/div :.incomplete-action ($/not $/last-child))))
I haven’t used this in a while but I remember when I was doing a lot of CSS with Garden I did this sort of thing frequently and it gave me a ton of control.
Selectors are “sticky” too so you can then do something like.
(css/css
[($last-incomplete-action $/hover)
{:background "green"}])
;; =>
;; div.incomplete-actions > div.incomplete-action:not(:last-child):hover {
;; background: green;
;; }
Basically, you can use them either as a value or a function. As a value they end up being rendered as is. If you invoke them they accept other selectors as arguments and glue them together and give you an instance of the same kind of value/function thing.
Cool, I will focus on learning these selector patterns a bit better. at first glance, they are a lot more intuitive than what I was trying to do
I tried to make them work like they do in CSS. You have operators like >
, +
, etc. that work with the prefix notation e.g. (+ s1 s2)
. The others simply concatenate.