:nth-child(odd), :nth-child(even)

See image. So the idea is that the - becomes the color red on hover and the + the color green which should be simple bc the - is the odd child, the + is the even child but all of them return as odd... When I added it under only 1 image it worked just as intended, but when I added it to the other images, it no longer worked as intended... What am I doing wrong?
No description
53 Replies
ἔρως
ἔρως4w ago
because they are on 1st and 3rd positions, and both are odd also, the buttons don't have a value or anything set a value and use the value to target them in css
Brightie
Brightie4w ago
oh, I see, for some reason I was thinking its looking at the amount of this specific child (so .blabla button) instead of its position in according to its parent element
ἔρως
ἔρως4w ago
no, it's looking at the position of every single child
Brightie
Brightie4w ago
haven't really used the :nth-child that often yet, so that's why I was thinking itd look at it this way thanks for the information!
ἔρως
ἔρως4w ago
the of <selector> version does what you want, but it's not the tool you need as i said, set a value on the buttons and target the buttons by the value not their position in the html
Brightie
Brightie4w ago
yeh I'll do it that way, thanks for the information
ἔρως
ἔρως4w ago
you're welcome by the way, consider using scss your styles are starting to get really messy
Brightie
Brightie4w ago
ill take a look into that then I also think im overcomplicating the namings of my classes just a bit an maybe I should nest some instead
ἔρως
ἔρως4w ago
it's very overcomplicated your class name takes 25% the width of your screenshot
Brightie
Brightie4w ago
I agree on that one :p was thinking of making it more simple eventually but ill take a look into that scss
ἔρως
ἔρως4w ago
if you use a bundler already, like vite, you probably have half the work done "eventually" will never happen
Brightie
Brightie4w ago
nahh, eventually will happen, trust me xd Ive rewritten several other projects a few times bc I wasn't satisfied with how complicated it looked it actually even got me learning new things sometimes Anyway, css can nest as well, right? I just looked on the website of sass and it claims css cant do that yet but i would swear its already able to do so
ἔρως
ἔρως4w ago
yes, css can nest, but it works differently in some aspects
Brightie
Brightie4w ago
oh? how so
ἔρως
ἔρως4w ago
&_class <-- this is invalid in css, valid in scss
Brightie
Brightie4w ago
oh, but you can nest without using classes right? like & p and stuff? isnt that enough then?
ἔρως
ἔρως4w ago
there are other details yes, you can do that in css and scss
Brightie
Brightie4w ago
ill take a deeper look into it, thanks !
ἔρως
ἔρως4w ago
you're welcome what i was refering to is, for example, you have .card as the parent style you then can do &_title to create .card_title you can also use actual variables in selectors
Brightie
Brightie4w ago
ah I see, yeh that would be quite useful to simplify it indeed
ἔρως
ἔρως4w ago
for example:
@for $i from 0 through 9 {
p:nth-child("#{$i}") {...}
}
@for $i from 0 through 9 {
p:nth-child("#{$i}") {...}
}
Brightie
Brightie4w ago
I take it such things wouldn't work in regular css xd alright, time to take a llook at scss then what's the vite thing about by the way? you said its a bundler, do you mean that it would automatically do this for me or how am I meant to understand that
ἔρως
ἔρως4w ago
yeah, those things dont exist in css and vite is a bundler it helps pack all the js nice and tight and the css too it can automatically compile typescript and scss for you
Brightie
Brightie4w ago
I see, ill take a look into that as well then
ἔρως
ἔρως4w ago
you should, it may help you too
Brightie
Brightie4w ago
I mean, no doubt it would help out :p clean code is easier to read I say that while my classnames are a whole screen long lmao
ἔρως
ἔρως4w ago
lol could be worse at least it's indented
Brightie
Brightie4w ago
true, but that's also because I have prettier css extention, it helps out with that when im too lazy to do it myself
ἔρως
ἔρως4w ago
some people dont even do that
Brightie
Brightie4w ago
fair fair, im currently simplifying the names Im not sure what I was even thinking when I did actionCard__card__container like, what purpose does the second card have, makes no sense, should just be actionCard__container or this giftcards__cards__actions__container why did I put twice cards lol, can just do giftcard__actions__container
ἔρως
ἔρως4w ago
maybe .giftcard--container
Brightie
Brightie4w ago
yeh that works too, still figuring out what style works best, underline or just a -
ἔρως
ἔρως4w ago
or .giftcard--actions you know, simple names plural for containers, singular for elements not quite BEM-like, but gets close
Brightie
Brightie4w ago
yeh that's the idea behind it i heard somewhere xd I mean, even if its not bem, it sure as hell is a whole lot better than what I did with my names
ἔρως
ἔρως4w ago
oh, yeah, it's leagues and bounds better
Brightie
Brightie4w ago
geez :(( anyway, ill get going now with fixing up the names and looking into scss & vite once again, thanks for the help!
ἔρως
ἔρως4w ago
it's what i use the most, personally it keeps names short but hey, saying it's better doesn't mean you had it bad before
Brightie
Brightie4w ago
yeh thats true Im not sure what my idea was with making them so long n complicated literally wrote them wrong a fewtimes when writing them down again lmao
ἔρως
ἔρως4w ago
well, you need a dictionary and autocorrect?
Brightie
Brightie4w ago
true true, it couldve been worse
ἔρως
ἔρως4w ago
it could, but luckly it isnt
Brightie
Brightie4w ago
no.. I sometimes just put only 1 _ or like I forget I put cardS instead of card, why I made those plural as well Im not certain
ἔρως
ἔρως4w ago
well, it's a container, and there's many containers so
Brightie
Brightie4w ago
yeh but, theyre not always containers, yet I put for everything cardS even if its just talking about the actual card and not the container like actionCards__cards is something I had, luckily I changed them now
ἔρως
ἔρως4w ago
hey, we all do things we don't get
Brightie
Brightie4w ago
trueeee xd right well ill get to it now!
ἔρως
ἔρως4w ago
i do write a lot of crappy code myself
Brightie
Brightie4w ago
esp if youre tired
ἔρως
ἔρως4w ago
good luck
Brightie
Brightie4w ago
:') I once wrote a code in the middle of the night, the next day I told myself yeh never again at night
ἔρως
ἔρως4w ago
that's when i write the best code 3am code is something else
Brightie
Brightie4w ago
I couldn't understand nomore what on earth I wroote down wouldve needed 5 dictionaries I think
ἔρως
ἔρως4w ago
lol i know the pain
Want results from more Discord servers?
Add your server