Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Daniel Campbell
Daniel Campbell
10,148 Points

Dynamic pagination using CSS

Hello, this is my first post and work example for CSS. I made a website to try out some things.

http://kiti.ca

The site is a single html page with internal pagination, like a book.

Goal: Insert a new page in the pagination and have the numbered anchors (#p1, #p2) and up/down arrows (which reference the anchors) update responsively if I INSERT pages into the pagination.

I would need to generate the page anchors (#p1, #p2, etc... ) with CSS.

I would like to insert a page and the <id="#p1"> anchors and links <a href="#p1"> update according to the order they appear in the html document. If I move a page all references to page id's anchors should update (#p__).

I need to search for, match, and modify instances of “id=#p__” , then dynamically concatenate the number to result in id=“p#(page number)”.

The question: Is it possible to use css pseudo classes or other CSS method to dynamically control pagination?

a[id^=“p”] {
  /* add number to anchor based on order in HTML doc */
}

or:

ol.pagination a[rel=""] /* anchor link to previous page */
ol.pagination a[rel=""] /*  anchor link to next page */

I know it’s possible with javascript but I’m trying to understand the scope of CSS. It’s also possible to change the anchor names to ‘cleaning’, ‘food’, and then be able to insert or move pages in the HTML document, but again, I’m trying to learn a dynamic method for the pagination with CSS via dynamically created page numbers/anchors/links.

Thanks for helping!