Is this possible without JavaScript (CSS)?

Status
Not open for further replies.
I've littered too many threads with 19 example fails. Here's a new approach.

Using fully fluid layout so it uses 100% of the screen (device/desktop), is it possible to have these two things:

1. A left resizing navigation column who's size is based on available percent size. Say, 25% of available space for fun.

This nav, once clicked, should act like finder on MacOS where the nav slides left (so main nav slides left, out of view) and the subnav for that selected item slides in from the right, vertically aligned top.

So the top of the subnav is the same as the main nav. This rules out nesting subnav inside a main nav item (sorry SEO).

2. There is a back button which reverses this so subnav slides right at the same time main nav slides right back into view, making subnav disappear and main nav reappear.

~

So a fluid width left nav that slides left to reveal subnav. The main and subnav are the same width. Each nav pushes the other entirely out of the way.

With known pixels this is trivial. If I can do it with percents this would be so much easier. Ideas?

Thanks

Edit:

Love the news but the forums which were nearly chat rooms have slowed to, well, dead.

I've been having a lot more success at Adobe. Launched a day ago is Adobe Code Corner (https://forums.adobe.com/community/codi ... er/content). Answers in either space, being a decade old subscriber and helper, is appreciated. Didn't post there yet but I don't know where else to post.

Thanks
 

krimhorn

Ars Legatus Legionis
39,865
[url=http:/civis/viewtopic.php?p=29690023#p29690023:109qakv0 said:
ominous[/url]":109qakv0]Love the news but the forums which were nearly chat rooms have slowed to, well, dead.
This forum is still fairly active. There was never a time when you were going to get hundreds of answers (StackOverflow is your friend if you need a lot of variety in answer) but the ones you do get are likely to be on point.

Anyhoo, to your question: Ravenstroke's got the right of it. What you want to do can be done with CSS in terms of the nav layout but you need to be juggling CSS classes to do it. That implies Javascript. I don't think you need to worry about keeping track of state, simply adding/removing classes based on what classes are currently on the elements should do it (i.e if you have classes called .left-nav-open and .left-nav-closed then you select based on those and perform the appropriate swap for the open/close action).
 
Both interesting and please absolutely do no take my comment on pace here too much to heart. I deal with hundreds of posts on Adobe a day myself but yes, StackOverflow is the leader at the moment, hence Adobe Code Corner.

That aside, how much am I going to be a downright dirty developer measuring screen space via JavaScript, essentially abandoning CSS as a purist answer? Did I really get the right wind off the bat that this just cannot be achieved in CSS alone or am I ignorant of some simple CSS3 concept? I hope the latter.
 

krimhorn

Ars Legatus Legionis
39,865
[url=http:/civis/viewtopic.php?p=29691287#p29691287:lgbue8kc said:
ominous[/url]":lgbue8kc]That aside, how much am I going to be a downright dirty developer measuring screen space via JavaScript
You shouldn't have to do your measurements in js, just the management of which classes are active based on reactions to the user's inputs.
 

gnosis

Ars Tribunus Angusticlavius
8,339
I don't think it's that crazy. The user is toggling the state of the display of some thing. Semantically, a checkbox is a great match. Paired with a label that explains what the checkbox does (or visually represents it, like say a hamburger), it's certainly not going to confuse a user. It has the benefit of being usable by users who disable JavaScript, as well as users with accessibility solutions that handle JS poorly.

The CSS selector is really the only thing that's "hacky", but it's simple enough with pick_your_favorite_preprocessor to give it a maintainable name.
 

krimhorn

Ars Legatus Legionis
39,865
If you're displaying the checkbox then, yeah, it's not as bad a decision. The sources I was seeing were saying to hide the checkbox and now you've got some DOM structure that's totally unclear what it's doing without digging through CSS looking for a sibling selector that may or may not be there. And why would you go looking for that in the first place? Even if it's not hidden there's nothing that really conceptually connects the checkbox to the state of the page. At least if it's not hidden it's obvious that when the checkbox is in one state the page is in another which should lead you to looking for the trigger.

Still, I prefer my js libraries that let me do things like:
Code:
<div class="top-nav">
    <button ng-click="someStateVar = !someStateVar">Toggle</button>
    <div class="left-nav" ng-hide="someStateVar">
      //stuff
    </div>
    <div class="right-nav" ng-hide="!someStateVar">
      //different stuff
    </div>
</div>

Now with the checkbox we could have the same thing conceptually:
Code:
<div class="top-nav">
    <input id="toggle" name="toggle" type="checkbox" ng-model="someStateVar"/>
    <label for="toggle">Toggle</label>
    <div class="left-nav" ng-hide="someStateVar">
      //stuff
    </div>
    <div class="right-nav" ng-hide="!someStateVar">
      //different stuff
    </div>
</div>

A bit more verbose to get the same net effect but depending on what you want from the view acceptable.
 

gnosis

Ars Tribunus Angusticlavius
8,339
I'm not sure why an implementation should be evaluated on the ability to inspect it from a user point of view. If the checkbox is hidden, it is easy to determine the mechanism in code because the clickable element will be a label, and its target input is deterministic. Even if the approach is unfamiliar, the semantics are clear and the mechanics are easy to evaluate in source.

I would have no difficulty determining how this works, and it doesn't require an enormous MVC framework in order to surface logic and make it look marginally declarative:

Code:
<div class="top-nav">
    <label for="nav-visible">Toggle</label>
    <input id="nav-visible" type="checkbox">
    <div class="nav">
        <!-- stuff -->
    </div>
</div>

Edit: copypasta -> correct HTML
 

krimhorn

Ars Legatus Legionis
39,865
[url=http:/civis/viewtopic.php?p=29695501#p29695501:nn4odpx6 said:
gnosis[/url]":nn4odpx6]I'm not sure why an implementation should be evaluated on the ability to inspect it from a user point of view.
I couldn't care less about the user's perspective (regarding the implementation being discussed). If I've got to maintain something it needs to be reasonably clear as to what's going on. If the only reason to use an unclear, if not outright obtuse, hack is to avoid a small amount of low-impact javascript then it's a bad idea from a maintenance perspective. At this point JS engines are nearly (if not as) fast as DOM/CSS rendering in browsers so it's not like there's a great justification for unclear hacks to obtain js-like functionality.
 

gnosis

Ars Tribunus Angusticlavius
8,339
I couldn't care less about the user's perspective (regarding the implementation being discussed). If I've got to maintain something it needs to be reasonably clear as to what's going on.
Then I don't understand why it makes a difference if the checkbox is visible or not. You're maintaining and presumably reviewing the code. If you received the above snippet, would you be confused when the checkbox that implemented the toggle behavior wasn't visible?

If the only reason to use an unclear, if not outright obtuse, hack is to avoid a small amount of low-impact javascript then it's a bad idea from a maintenance perspective.
That isn't the only reason.

it's not like there's a great justification for unclear hacks to obtain js-like functionality
There are many reasons developers might elect not to use JavaScript at all.
 

krimhorn

Ars Legatus Legionis
39,865
[url=http:/civis/viewtopic.php?p=29695807#p29695807:3uv8putz said:
gnosis[/url]":3uv8putz]
Then I don't understand why it makes a difference if the checkbox is visible or not. You're maintaining and presumably reviewing the code.
You're using an element for something it's not intended for, to control state on an unrelated element and if hidden have absolutely no way of knowing that's what it's for. At least if it's visible when you come in to maintain the page you can see the effect occurring as the checkbox changes state (though it's still totally unclear how it's happening). I don't particularly care if it is the new hotness right now, it's a fad that will fade and then you're faced with coming back to maintain a page that has a design rooted in a passing trend and are stuck auditing everything about it unless you manage to remember that buried somewhere in your CSS is a sibling selector that causes the effect to occur.

If you're concerned about the 1% of people who don't have Javascript enabled: don't. Fall back to something non-flashy but functional for them. If you really don't want to use Javascript yourself then rely on standard practices and don't bother with flashiness at all. The site doesn't need a flashy, multi-state nav in order to operate but if it's going to have one it should be driven by a function in a script that you can name clearly and hooked to an event that's obvious and discoverable.

Build something that's obtuse and it's a pain to maintain and you will regret it when you come back after forgetting how it was built. That's a guarantee.

If you received the above snippet, would you be confused when the checkbox that implemented the toggle behavior wasn't visible?
If I received the above snippet the first thing I'd be doing is cursing the person who did it as I tried to figure out where the effect was coming from. Once I did it would be promptly removed and either rendered static (if I was forbidden from using Javascript) or replaced with a clearer actor for the functionality (i.e. a function named something along the lines of toggleNavVisibility(event)).
 
Status
Not open for further replies.