I am trying to develop a single-screen, pure css website interface that allows a User to click through a series of choices. The goal is to allow the User to self-select their way to a desired action (signup, contact form, load a new page, etc).
My approach was to put several absolutely positioned divs in a relatively positioned wrapper, then use a combination of z-index and :target to achieve the desired result.
The issue I am encountering is the transition between slides (each slide displays two choices the User can make). In the first test (A/B Slide Choice Test (Working) the transtion works by sliding divs from left to right. The two subsequent slides are absoultely positioned to right:100%, then right:0 using :target
#target2:target {
right: 0;
}
#target3:target {
right: 0;
}
#target1, #target2, #target3 {
transition: all 0.6s ease-out;
}
#target1 {
z-index:1;
}
#target2 {
z-index:2;
right: 100%;
}
#target3 {
z-index:3;
right: 100%;
}
The result is working as desired - when clicking on choice 1A or 1B, the transitions are occuring and the correct slides are displayed.
But in the second test, A/B Slide Choice Test (not working), the two subsequent divs, Slide 2 and 3, are absoultely positioned to left:100%, then left:0 using :target
#target2:target {
left: 0;
}
#target3:target {
left: 0;
}
#target1, #target2, #target3 {
transition: all 0.6s ease-out;
}
#target1 {
z-index:1;
}
#target2 {
z-index:2;
left: 100%;
}
#target3 {
z-index:3;
left: 100%;
}
Several things are happening:
Clicking on decision 1A:
- Result: Slide 3 (#target3) moves into position without transition.
- Expected: Slide 2 (#target2) slides in from the right side of the screen.
As near as I can tell, clicking on 1A is activating the wrong target and/or Slide 2 and 3 are both moving to the left (with Slide 2 being pushed all the way offscreen to the left). Then if you click choice 3A the transition works properly (slides back to the right, revealing Slide 1 again)
Clicking on decision 1B:
- Result: Slide 3 (#target3) suddenly appears, and moves to offscreen (to the left) with transition, revealing Slide 2 (#target2).
- Expected: Slide 3 (#target3) slides in from the right side of the screen.
Then if you click choice 2B the transion works properly (the sldie goes back to the right, revealing Slide 1 again)
I have tried this absolutely positioned transition using using top:100% and top:0, and bottom:100% and bottom:0
The same issue occurs: Using absolutely positioned 'top' values works, while 'bottom' values creates the undesired behavior.
I want to be able to use transtions in any direction, the ultimate goal being that 'direction' will be a configurable backend parameter in a Joomla module. The module is actually written, installed, and working properly except for this transition issue.
I don't know if :target is somehow breaking the desired behavior, or if I'm doing something wrong with absolute positioned CSS values, or both. Or if my (limited) understanding of Flexbox is messing things up.
I am completely open to using a different method of getting the desired behavior shown in the working version (ideally using CSS only) if that's what is required.
But so far in my internet searches I haven't found any code snippets or examples of the one-screen A/B interface I am trying to accomplish.
I am extremely grateful for any assistance!
EDIT: I've been playing around with values to see if I can get a better understanding of what's going on.
#target2:target {
left: 100%;
}
#target3:target {
left: 100%;
}
#target1, #target2, #target3 {
transition: all 0.6s ease-out;
}
#target1 {
z-index:1;
}
#target2 {
z-index:2;
left: 100%;
}
#target3 {
z-index:3;
left: 100%;
}
In theory (as far as my understanding goes), with the CSS above, there should be no change as both values are left:100%
But in practice clicking on decision 1A or 1B causes #target2 and #target3 to move onscreen (though without transition).
Then I added multiple slides into the relatively positioned wrapping div, and what I've found is that all the slide IDs are affected (#target2, #target3, #target4, #target5 etc.).
Again my understanding is that clicking on the href="#target2" should only affect #target2:target, but it is affecting all other slide IDs, making me think that position:absolute and :target are conflicting somehow.
(bangs head on desk)