: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
ἔρως
ἔρως2mo 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
BrightieOP2mo 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
ἔρως
ἔρως2mo ago
no, it's looking at the position of every single child
Brightie
BrightieOP2mo 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!
ἔρως
ἔρως2mo 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
BrightieOP2mo ago
yeh I'll do it that way, thanks for the information
ἔρως
ἔρως2mo ago
you're welcome by the way, consider using scss your styles are starting to get really messy
Brightie
BrightieOP2mo 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
ἔρως
ἔρως2mo ago
it's very overcomplicated your class name takes 25% the width of your screenshot
Brightie
BrightieOP2mo ago
I agree on that one :p was thinking of making it more simple eventually but ill take a look into that scss
ἔρως
ἔρως2mo ago
if you use a bundler already, like vite, you probably have half the work done "eventually" will never happen
Brightie
BrightieOP2mo 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
ἔρως
ἔρως2mo ago
yes, css can nest, but it works differently in some aspects
Brightie
BrightieOP2mo ago
oh? how so
ἔρως
ἔρως2mo ago
&_class <-- this is invalid in css, valid in scss
Brightie
BrightieOP2mo ago
oh, but you can nest without using classes right? like & p and stuff? isnt that enough then?
ἔρως
ἔρως2mo ago
there are other details yes, you can do that in css and scss
Brightie
BrightieOP2mo ago
ill take a deeper look into it, thanks !
ἔρως
ἔρως2mo 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
BrightieOP2mo ago
ah I see, yeh that would be quite useful to simplify it indeed
ἔρως
ἔρως2mo ago
for example:
@for $i from 0 through 9 {
p:nth-child("#{$i}") {...}
}
@for $i from 0 through 9 {
p:nth-child("#{$i}") {...}
}
Brightie
BrightieOP2mo 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
ἔρως
ἔρως2mo 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
BrightieOP2mo ago
I see, ill take a look into that as well then
ἔρως
ἔρως2mo ago
you should, it may help you too
Brightie
BrightieOP2mo 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
ἔρως
ἔρως2mo ago
lol could be worse at least it's indented
Brightie
BrightieOP2mo 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
ἔρως
ἔρως2mo ago
some people dont even do that
Brightie
BrightieOP2mo 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
ἔρως
ἔρως2mo ago
maybe .giftcard--container
Brightie
BrightieOP2mo ago
yeh that works too, still figuring out what style works best, underline or just a -
ἔρως
ἔρως2mo ago
or .giftcard--actions you know, simple names plural for containers, singular for elements not quite BEM-like, but gets close
Brightie
BrightieOP2mo 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
ἔρως
ἔρως2mo ago
oh, yeah, it's leagues and bounds better
Brightie
BrightieOP2mo ago
geez :(( anyway, ill get going now with fixing up the names and looking into scss & vite once again, thanks for the help!
ἔρως
ἔρως2mo 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
BrightieOP2mo 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
ἔρως
ἔρως2mo ago
well, you need a dictionary and autocorrect?
Brightie
BrightieOP2mo ago
true true, it couldve been worse
ἔρως
ἔρως2mo ago
it could, but luckly it isnt
Brightie
BrightieOP2mo 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
ἔρως
ἔρως2mo ago
well, it's a container, and there's many containers so
Brightie
BrightieOP2mo 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
ἔρως
ἔρως2mo ago
hey, we all do things we don't get
Brightie
BrightieOP2mo ago
trueeee xd right well ill get to it now!
ἔρως
ἔρως2mo ago
i do write a lot of crappy code myself
Brightie
BrightieOP2mo ago
esp if youre tired
ἔρως
ἔρως2mo ago
good luck
Brightie
BrightieOP2mo ago
:') I once wrote a code in the middle of the night, the next day I told myself yeh never again at night
ἔρως
ἔρως2mo ago
that's when i write the best code 3am code is something else
Brightie
BrightieOP2mo ago
I couldn't understand nomore what on earth I wroote down wouldve needed 5 dictionaries I think
ἔρως
ἔρως2mo ago
lol i know the pain
Want results from more Discord servers?
Add your server