This forum is now read-only. Please use our new forums at discuss.codecademy.com.

CSS Selectors Forum

View Course

965 points
5613365386f552a825000009_16624411
Submitted by
raphnov
about 2 years ago

Is it possible to use nth-child(n) as a function?

I know it is not the purpose of this class, and maybe I'll need to use Python or Ruby to rewrite the css file every time a website contents is refreshed, but it happens to me to build a function that can walk through RGB colors and brings the hexadecimal value to use the next color after last used.

For example,

for i in all i in the html_page
a:nth-child( i ) {
color: function();
}
i = i +1
loop

1 vote

permalink

you might be able to use sass for this, from sass website :
Sass is the most mature, stable, and powerful professional grade CSS extension language in the world.

I would personally not use python and ruby for this, they are more used for backend development.

I am slightly confused by the question, and especially by this bit: every time a website contents is refreshed

For every user to use your website you want different colors? People rarely refresh webpages, or do you mean refresh the page to load additional/new content?

2937 points
593d545c83696644420003b7_64554016
Submitted by
stetim94
about 2 years ago

1 Comment

5613365386f552a825000009_16624411 raphnov about 2 years ago

Yeah, I mean refresh the page to load additional/new content, but specifically, new contents. =)


0 votes

permalink

Okay, now i understand. Another question: where does the content come from? or didn't have you have a plan of building something?

Anyway, when loading in new content, i would recommend to use ajax (which is more complicated) but ajax allows you to load in content dynamically without refreshing the page. ajax stand for asynchronous javascript and xml, so you can use javascript to color your content. Or if you are planning on using ajax + jquery you can use jquery to do the coloring.

I think that is the best option, but that also depends on the situation

2937 points
593d545c83696644420003b7_64554016
Submitted by
stetim94
about 2 years ago

4 Comments

5613365386f552a825000009_16624411 raphnov about 2 years ago

I got it. Building function for customizing directly on CSS doesn't work, I need to do it on a front-end coding.
I have not planned anything yet, but I was thinking about a blog template that shows the newest contents as headers on top to bottom of the page, but the old headers gets lighter color while I scroll down through the page. Thanks man =)

593d545c83696644420003b7_64554016 stetim94 about 2 years ago

well, maybe you can achieve this with sass, which is technically a css framework i think. But i have very little experience with sass. Well, i hope my information was a bit useful. You are welcome

5613365386f552a825000009_16624411 raphnov about 2 years ago

yes. It was =) thank you so much. I did not know such a framework for CSS actually exists. =) It was very helpful. Well I don't know it is possible through coursera, but I'm looking for other developers who I can develop with, following this helpful article http://www.vikingcodeschool.com/posts/why-learning-to-code-is-so-damn-hard, if you are interest on, please, let me know.

593d545c83696644420003b7_64554016 stetim94 about 2 years ago

if you want to develop with other people, learn github. github is heaven for collaboration programming. Well, we could work together