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