Transform translate has wierd behavior on keyboard focus in Chrome - html

I am developing a navigation side bar which should show some data when closed, and the reveal it all when hovered or focused via keyboard navigation (just using the tab button in this case). It works by having an inner container which I translates opposite of the outer container thus being able to show some content even when it is closed. It works perfectly fine when hovering, but when navigated to with keyboard events (tab button), the inner container suddenly translates itself the wrong place. If I remove and apply the translate class again on the inner class it translates back to where it should.
I find it weird that the inner container just translates itself on focus. And even weirder that it does not seem to be reflected in the CSS of the element, that I can just remove and reapply the same class and then it works.
A minimum reproducible example is found here: https://codepen.io/kasperlauge/pen/dyoaxKJ
Code for this is:
HTML:
<h1>Hover this list to reveal more...</h1>
<div class="outer">
<div class="inner">
<button type="button">abcdefghijklmnopqrstuvxyz</button><br/>
<button type="button">abcdefghijklmnopqrstuvxyz</button><br/>
<button type="button">abcdefghijklmnopqrstuvxyz</button><br/>
<button type="button">abcdefghijklmnopqrstuvxyz</button><br/>
<button type="button">abcdefghijklmnopqrstuvxyz</button><br/>
<button type="button">abcdefghijklmnopqrstuvxyz</button>
</div>
</div>
CSS:
.inner, .outer {
width:200px;
overflow:hidden;
transition:all 0.3s;
}
.inner {
transform:translateX(150px)
}
.outer {
transform:translateX(-150px);
background-color: #BBB;
padding: 10px;
}
.outer:hover,
.outer:hover .inner {
transform:translateX(0)
}
When not hovered/focused:
When hovered (right behaviour):
When tabbed to (wrong behaviour):
Can somebody help?

I actually did solve it for my case, but unfortunately it does not generalize to the codepen provided in the question, thus I still would like to see a good solution to that in Chrome and Edge, as Firefox do not generate the faulty scrolling.
The way I solved it in my case was by reducing the width of the buttons to make them fit within the non revealed stuff. It works in our case because we have three states of revealing in our menu and it only have to fit within the two first states.

Related

Put buttons under each other that don't leave space when hidden

I'm trying to create a Navigation field for my website, and I would like my buttons to be underneath each other with a white line in between. I have managed to get this part working by adding two line breaks next to the button, as seen here:
<button id = "next" onclick="next()">
Volgende
</button><br><br>
I'm wondering if it's possible to have them show up like this, but if I hide the button, have the other buttons jump up, so they fill the gap and jump back down when the button becomes visible again.
Thanks in advance!
Don't use line breaks for layout. That's a misuse of their purpose, which is to break text.
Just put your buttons in block-level (or inline-block level) containers, like divs. Obviously you'd hide and show the containers, not the buttons.
.button-container:not(:first-child) {
border-top: 1px solid red;
padding-top: 4px;
margin-top: 4px;
}
<div id="next-btn-container" class="button-container">
<button id="next" onclick="next()">Volgende</button>
</div>
<div id="other-btn-container" class="button-container">
<button id="other" onclick="next()">Volgende</button>
</div>
<div id="another-btn-container" class="button-container">
<button id="another" onclick="next()">Volgende</button>
</div>
<br> is not a good practice for cross-browser perspective, kindly use the standard way by using margin and display:block property of css.
So your html will be like:
<button class="mb-20px d-block" id = "next" onclick="next()">
Volgende
</button>
And add below line in your css
.mb-20px { margin-bottom: 20px; }
.d-block { display: block; }
I have found how to make it work.
Instead of using
document.getElementById("button").style.visibility = 'hidden'
I have now used
document.getElementById("button").style.display = 'none'
This makes the buttons fill the gaps when they're hidden.

NVDA Skips first focusable element on initial page load when tab pressed

Recently while attempting to make my site accessible I stumbled upon a bizarre problem. During the process of setting up a 'skip navigation' link, I noticed that when the page is initially loaded (by 'initially loaded', I mean in a clean browser session, not on refresh—as NVDA keeps a track of the last focused element so results would be dependent on that).
When the page loaded and the tab key pressed, the element that received focus was the 2nd element (which as you will see from the below simplified example, is the site logo/name (also an anchor link)).
The problem doesn't show when NVDA is not running... everything works as expected, Firefox works perfectly fine with or without NVDA running but the problem is present in Chrome, Edge and Opera desktop. I've not tested it on any other browsers thus far.
Please note, because of the nature of the problem, I didn't include a runnable code snippet or fiddle (as there would be other elements on the screen and, as I said this problem only shows with a new browser session/clean page load. Here is some simplified code to show the problem...
CSS
body, html {
margin: 0;
}
.skip-nav {
position: absolute;
margin: 10px 0 0 10px;
white-space: nowrap;
display: inline-block;
padding: 0;
}
.skip-nav a {
position: absolute;
left: -1000px;
border: 2px solid blue;
border-radius: 2px;
background-color: black;
padding: 5px;
}
/* Move link into viewport when focused */
.skip-nav a:focus {
left: initial;
}
nav {
display: flex;
align-items: center;
justify-content: space-between;
height: 30px;
background-color: darkblue;
padding: 10px;
color: white;
}
nav ul {
list-style: none;
}
nav li {
display: inline;
margin: 0 5px 0 5px;
}
a {
text-decoration: none;
color: white;
}
a:hover {
color: rgb(165, 165, 165);
}
HTML
<!-- Should get focus first, only does in FF when NVDA is running, not in other tested browsers -->
<div class="skip-nav">
Skip navigation
</div>
<!-- Dummy nav bar -->
<nav>
Name
<ul>
<li>Home</li>
<li>Services</li>
<li>About</li>
<li>Contact</li>
</ul>
</nav>
<!-- Main site content -->
<section id="main-content">
Lorem ipsum dolor sit amet consectetur adipisicing elit. Animi dolores voluptates temporibus culpa in quia et magni laborum architecto fugit!
</section>
Things I have tried
The first thing I did was to disable all my browser extensions/test in Chrome incognito mode. Then I tried in the other browsers mentioned above. I also tried other focusable elements (such as a button and even a div with the 'tabindex=0' attribute set. I also put my initial link on its own (not within a parent div). All gave the same results.
Workaround
Instead of placing the link in a div, I put it in an ul/li... and it works perfectly...
<!-- Using a UL works... but not with bullets hidden
<ul class="skip-nav">
<li>
Skip navigation
</li>
</ul>
So I thought I would just set the list with the following property in my CSS...
list-style: none;
The bullet disappears but the problem returns...
For now, I've stuck with the 'fix', but instead of setting the list-style to none I've simply removed the padding from the list so that when it's over to the left side of the screen, the bullet remains off-screen and hidden. I've tested this in all browsers and it works, save for the fact that screen readers still read and announce the 'bullet' when traversing elements (in NVDA, using the arrow keys). Not a massive deal-breaker but this seems a very 'hacky' way of achieving (something close to) the desired result.
Just to summarise, to reproduce the problem the browser must be a new session. With the page loaded, the first tab press should focus the link in the 'skip-nav' div. Currently with the above example the initial tab seems to ignore the first link (unless in a bulleted list). However, shift-tabbing backwards then does focus the link as would be expected.
Is there something I'm missing?
This is a visual focus problem, when you load the page focus is placed on the document (by the browser) and the first link is already focused (by NVDA) if it isn't wrapped in a <ul>. NVDA also doesn't report that the item is focused using NVDA + Tab.
However if you press Space to activate the link you will see it is indeed focused as the URL updates.
My guess is it is something to do with how NVDA places the review cursor when focus changes programatically and how it interacts with the first item on the page.
Also if you put focus into the URL bar after the page loads (resetting the focus) and Tab into the document it behaves as expected.
This appears to be a long standing bug but I couldn't find any answers as to what particular part of the process causes this. It is also a bug I was unaware of until today so I will do some more digging (my sites are affected by this).
The only thing I can think is that the browser focuses the document the first link on the page is the first text and when the review cursor is placed on it it assumes that the link is activated (or focus is set by NVDA before the document is rendered...pure conjecture though).
How to fix for yourself
One way around this is to change your settings in NVDA.
Right click NVDA icon -> Preferences -> Review cursor... -> uncheck "Follow system focus".
At that point you will see that the first item on the page is automatically focused correctly.
How to fix for everyone else
It is debatable whether it needs fixing, Tab is not used as often as other methods by screen reader users and with the fact it is only on a brand new session (I mean I have never noticed it and I use a screen reader often, albeit only for testing not as a full time user) I imagine most people will not be affected.
As it only appears to happen if the first text on the page is a link you could work around it perhaps (I haven't had chance to test) by adding a span before it with a space.
<div class="skip-nav">
<span> </span>
Skip navigation
</div>
I will return to this question after some testing of the above but it may take a couple of days before I get chance.
Update
I was correct it seems, adding a span with a space fixes the issue and focus is shown correctly.
full HTML tested in the fiddle below, just added <span> </span> into the <header>, the first link then shows focus as expected:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NVDA focus Test</title>
</head>
<body >
<header>
<span> </span> <!---------------THIS IS WHAT I ADDED------------->
I should focus on first tab press
I should focus on second
</header>
<section style="margin-top: 20px;">
<p>
When you press tab after this page has loaded (at least for me), the initial tab press will focus the <i>second</i>
link for some reason.
</p>
<p>
This seems to happen however I present the link (on its own, wrapped in a div, section, or even a ul/li with the
list-style set to 'none') :-(.
</p>
</section>
</body>
</html>

How to hide buttons behind image text and make them stay in the same place across all devices?

I would like to hide two buttons, which I have achieved using transparent.
I've also managed to hide them behind two hand written words in a picture, post and search. The problem is that when it comes to desktop, different screen sizes, mobile/tablet, different screen sizes/browsers, operating systems etc, the buttons don't match the text, being either too high or too low, depending on device etc.
It works if I set one place for mobile and one for desktop, but as soon as anything changes like screen size, the text and buttons mis-match so that the picture text becomes unclickable. It's the effect I'm trying to achieve which is like the user is clicking on handwriting when in fact it's just a hidden button on the image.
Also tried to cut the buttons out of the image and use background: url but it didn't work and just cropped the image in the wrong place, hiding the word.
The only solution I can think of is if there is some way of telling the browser not to move the image regardless of screen size etc.
.btn.btn:hover {color: transparent! important; background:
transparent! important; border: none! important;}
btn.btn:active {color: transparent! important; background:
transparent! important; border: none! important; box-
shadow:none;}
.btn.btn {color: transparent! important; background:
transparent! important; border: none! important;}
Html
<div id="content" class="main-container">
<section class="content-area pt0 ">
<div id="main" class="" role="main">
<div id="shapely_home_parallax-3" class="widget
shapely_home_parallax"><section class="cover fullscreen
image-bg"><div class="parallax-window fullscreen" data-
parallax="scroll" data-image-src="https://adsler.co.uk
/wp-
content/uploads/2019/07/IMG_20190706_112754.jpg"
data-ios-fix="true" data-over-scroll-fix="true" data-android-
fix="true"><div class="align-transform"><div class="row">
<div class="top-parallax-section"><div class="col-md-8
col-md-offset-2 col-sm-10 col-sm-offset-1 text-center">
<div class="mb32"></div><a class="btn btn-lg btn-white"
href="https://adsler.co.uk/wp-user-test-dashboard-2.
2/awpcp-place-ad/">Post</a><a class="btn btn-lg btn-
filled" href="https://adsler.co.uk/search.
adsler/">Search</a>
</div></div><!--end of row--></div>
</div></div></section><div class="clearfix"></div>
</div>
</div><!-- #main -->
</section><!-- section -->
Just so you can get more of a sense of what is meant, the page is: https://adsler.co.uk
You can try to play with display: none and display: block tag arguments for your divs. This probably will require using JavaScript to change the property your your buttons. Something along the lines of when the first button is clicked it's display style is changed to none, and when the second one is clicked the first one's style is changed to block. onclick = "myFunction();" should do the trick. https://www.w3schools.com/js/js_functions.asp for reference on JS functions
It's the effect I'm trying to achieve which is like the user is clicking on handwriting when in fact it's just a hidden button on the image.
A much more effective way of achieving this effect will be to use an HTML image map. Using an image map will allow you to create arbitrarily shaped regions on an image that can be clicked like links.

How to get this search-results-div to show up on top of content, without interfering with nearby float elements?

I have a tricky layout that I'm trying to add type-to-search to. (The actual code uses Angular, but it looks like my problem is just the CSS.)
https://jsfiddle.net/dowxw1dz/2/
In a single TD, there are two floating bits off to the right (a descriptive label, and a button unrelated to the label). The main part of the TD is a text input, which takes up the remainder of the space. I'm trying to enhance the input by making it show a div with search results below it, overlaying the stuff below the input.
The problem I'm hitting is that the div containing the input is overflow:auto, so when the search results show up, they just add a scrollbar to the input div (with the search results visible if you scroll), rather than showing the search results on top of the other content. I could fix this by changing the overflow to something else, but then the two floating elements to the right decide to get out of the way of the input.
How can I get the search results to show over the lower content, rather than being trapped in the input div with a scrollbar? Ideally, I want the search results to be exactly as wide as the input (which is going to be variable), but my first problem is just to get the search results to show without either shoving around the floating elements or shoving the results behind a scrollbar.
HTML:
<div style="width:600px;">
<input type="button" value="Button!" style="float:right; width:100px;"/>
<span style="float:right"> Category </span>
<div class="inputRow">
<input type="text" id="input"/>
<div class="searchResults">
Results!
</div>
</div>
</div>
<div style="width:600px;">
There's other stuff that goes here. The searchResults div should cover this without pushing it out of the way. (The search results will be clickable to pick something, and then it'll go away.)
</div>
CSS:
.searchResults {
position:absolute;
top:100%;
background-color: white;
border: 1px solid black;
z-index: 50;
display: none;
}
.inputRow {
position:relative;
overflow:auto;
}
input {
width: 98%;
}
div {
z-index: 0;
}
JS:
$("#input").change(function() {
$(".searchResults").show();
});
It seems you need to use position fixed instead of position:absolute, and assign top:7% it will work. It's a way around. Still can't figure out why position:absolute is not working. I'm yet in the learning phase.
.searchResults {
position:fixed; /* instead of : position:absolute;*/
top:7%; /* instead of : top:100%;*/
background-color: white;
border: 1px solid black;
z-index: 50;
display: none;
}
Fiddle here : https://jsfiddle.net/nithin_krishnan/dowxw1dz/5/
The solution was simply to ignore the input element, and put the results in the content below the input, instead.
Unfortunately, that meant that setting the width had to be done in JavaScript instead of simply relying on CSS to do the right thing. I ended up using $(".searchResults").width($("input").width()) in order to make the width of the results match the width of the input. (And I removed the top: 100% from the .searchResults CSS class.)
https://jsfiddle.net/dowxw1dz/7/
<div style="width:600px;">
<input type="button" value="Button!" style="float:right; width:100px;"/>
<span style="float:right"> Category </span>
<div class="inputRow">
<input type="text" id="input"/>
</div>
</div>
<div style="width:600px; position:relative;">
<div class="searchResults">
Results!
</div>
There's other stuff that goes here. The searchResults div should cover this without pushing it out of the way. (The search results will be clickable to pick something, and then it'll go away.)
</div>

Image overflowing parent container in Firefox after jQuery scrollbar added

I'll try to keep this as succinct as possible...
I have a image that I had setup to fill it's parent div horizontally and scroll vertically.
I've since added a jQuery based scrollbar to replace the native scrollbar for non webkit browsers. Since doing so, my image is overflowing it's parent horizontally in Firefox. Chrome and IE are not having the issue.
It's a little convoluted because I'm using skelJS to set container sizes based on breakpoints, but I don't think that should make a difference. The parent and child containers along with the image have width's set.
I'm going to post the HTML and CSS first and see if there's something obvious I'm overlooking. The jQuery targets the .scroll-pane2 class and is working fine beyond my overflow problem. I'm happy to post that code if there isn't something obvious that I'm missing.
Thanks in advance for the help!
A summary of the code:
HTML:
<div class="8u tasting-menu">
<header>
<div class="scroll-pane2">
<p>Scroll or click for full-size menu</p>
<img src="images/bwh-tasting-list-png.png" class=""/>
</div>
</header>
</div>
CSS:
body {
width:100%;
}
img {
width:100%;
height:auto;
}
.8u {
width:66.6%;
height:auto;}
.scroll-pane2 {
height:27em;
width:100%;
overflow:hidden;
}
.tasting-menu img {
width:98%;
height:auto;
}
The jQuery based skelton I'm using accounts for the .8u. I've used it quite regularly and never had the issue, but I'll definitely take another look at it.
I tried the overflow-x:hidden to no avail. The jQuery scrollbar I'm using overrides the overflow in the scroll-pane2 class.
I need to relook at the scroll bar script I'm using... because before installation, it worked fine, albeit with the Firefox native scrollbars.
I'll try to put a jsfiddle together.