I'm trying to understand the accessibility styles from the theme, but they seem pretty overkill to me. Can someone please explain to me the reason for each line or group of lines so I can decide what is needed for my usage.
.screen-reader-text {
border: 0;
clip: rect(1px, 1px, 1px, 1px);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute !important;
width: 1px;
-wrap: normal !important;
/* Many screen reader and browser combinations announce broken
words as they would appear visually. */
}
.screen-reader-text:focus {
background-color: #f1f1f1;
border-radius: 3px;
box-shadow: 0 0 2px 2px rgba(0, 0, 0, 0.6);
clip: auto !important;
clip-path: none;
color: #21759b;
display: block;
font-size: 14px;
font-size: 0.875rem;
font-weight: bold;
height: auto;
left: 5px;
line-height: normal;
padding: 15px 23px 14px;
text-decoration: none;
top: 5px;
width: auto;
z-index: 100000;
/* Above WP toolbar. */
}
The .screen-reader-text class is for adding non-visual text (you can't see it) but the text is still in the DOM so that screen readers can access it. You use it to add extra text for screen readers. For example, if you had something like this:
<p>we sell cool stuff</p>
read more
The sighted user knows that "read more" refers to reading more about cool stuff. But a screen reader user, if they tab to the link, or if they bring up a dialog that shows all the links on the page, they'll just hear "read more". They'll be thinking, "read more about what?".
You can fix that by adding non-visual text such as:
<p>we sell cool stuff</p>
read more <span class="screen-reader-text">about cool stuff</span>
Now when the screen reader moves to the link, they'll hear "read more about cool stuff" but you won't see "about cool stuff" anywhere on the page.
Lots of third party libraries have a class such as this. For example, What is sr-only in Bootstrap 3?
As far as what each individual CSS property does, you can look that up. All of those properties are needed to get the "hidden" text to work across all browsers (firefox, ie, chrome, safari), screen readers (jaws, nvda, voiceover, talkback), and os's (pc, mac, ios, android). If you leave one of the properties out, it might work on the platform you're testing on but could break with a different combination.
.screen-reader-text applies to object you want to hide visually from screen but still render with a screen reader.
The different lines are different means of hiding the text while still making it readable by a screenreader.
The .screen-reader-text:focus will reverse the precedent style in order to make visible any object which has been focused with the screenreader, when the element is focused with the keyboard.
However, hiding text for screenreaders has to be considered a bad habit as screenreader users may also be sighted users (aphasic, paralytic, people with low vision) and those people may use a mouse or eye tracking devices, ...
Related
I'm having some issues with iOS ignoring a combo of align-self:flex-end and margin-bottom: 8px.
On Android devices, various Windows versions with Chrome and Firefox, and Chrome on macOS, #totalImg is displayed as I'd expect it to be - bottom right corner, slightly raised.
On Safri for macOS and Safari and Chrome for iOS, #totalImg is glued to the bottom.
See the following image for current behaviour:
I'm aware that I could get consistent cross-browser behaviour by applying bottom: 8px, but that seems to be working just in my test case, and fails in production, depending on the screen width of Android or iOS devices. For example, on Chrome for Android, with bottom: 8px, #totalImages can end up in the middle of its parent div, or well below it.
.image.big.j_launch {
display: flex;
display: -webkit-flex;
}
.image.big {
width: auto;
height: auto;
max-width: 320px;
margin-bottom: 10px;
float: none;
position: relative;
}
#totalImg {
display: block;
height: 15px;
position: absolute;
right: 11px;
background-color: rgba(0, 0, 0, 0.35);
padding: 2px 6px;
border-radius: 3px;
color: white;
font-size: 11px;
text-align: center;
align-self: flex-end;
margin-bottom: 8px;
}
<div class="image big j_launch" data-index="0">
<div id="totalImg"><span>1 / 18</span></div>
<img src="https://via.placeholder.com/320x240">
</div>
How can I get a consistent crossbrowser solution, which would place #totalImg as it's currently placed in the first image? Is there a reason for Safari (and iOS in general) to ignore what seems to be working on other platforms / browsers?
Looking at the document inspector in Safari, I can see that the margin is applied - there's an orange rectangle below #totalImg, which keeps growing / extending itself downwards, when I'm changing the margin-bottom value in the stylesheet inspector. It's just not being applied visually as I'd expect it to be.
While this is a solution, is not the best solution, and I'd recommend against it, even though it works.
First, a little bit of JavaScript is needed (as seen on this link).
var b = document.documentElement;
b.setAttribute('data-useragent', navigator.userAgent);
b.setAttribute('data-platform', navigator.platform );
b.className += ((!!('ontouchstart' in window) || !!('onmsgesturechange' in window))?' touch':'');
What this block does is that it adds two data attributes to the document itself (and a touch class if it's a handheld device). In my case - iPhone and Mac - data-platform had values of iPhone and MacIntel, respectively. classname and data-useragent are unnecessary in this context, but were not removed from the original code for illustrative purposes.
Next, add some new rules to CSS.
html[data-platform*='Mac'] #totalImg,
html[data-platform*='iPhone'] #totalImg {
bottom: 8px !important;
margin-bottom: unset !important;
}
This relies on partial macthings by the platform, and adjusts the rules accordingly - since bottom was recognized and applied on *OS devices, and margin-bottom was not, the rules are changed.
The reason I dislike this is that looks like a Rube Goldberg machine, and it's overly complicated for something that should've been solved in CSS alone.
Not to mention that it relies on a deprecated / obsolete feature.
The code is very straight-forward, see part of it below. Full example here:
Plain HTML:
<div class="test1">
<div class="silver1">
<span>test1</span>
</div>
<span>box 1</span>
</div>
CSS
.test1 {
border: 1px solid red;
width: 80px;
background-color: red;
}
.silver1 {
width: 30px;
height: 30px;
position: relative;
}
.test1:hover .silver1 {
top: 30px;
left: 80px;
border: 3px dotted blue;
background-color: yellow;
}
Tests:
Hovering with a mouse in any popular browser in either Windows or
Mac works fine.
By tapping the boxes on an Android Mobile it works
as well.
Tapping on Safari (iPhone/iPad) nothing happens.
Holding down on Safari sometimes work.
Question
How do I activate :hover for Safari iOS?
Ideally pure CSS solutions.
Try if with placing an :active after the :hover.
https://codepen.io/mausinc/pen/LgvmXv
.test1:hover:active .silver1 {
top: 30px;
left: 80px;
border: 3px dotted blue;
background-color: yellow;
}
Good luck
Well "hover" isn't a thing on touch interfaces.
Chrome mobile tends to call the first tap, hover if it's specified and a subsequent tap the same as a click. This functionality can get strange for users too. Safari, as you discovered, ignores it completely.
I would suggest that you try really hard to remove any content from hovers that users MUST do to complete a process or navigate and replace them with interaction specific paradigms.
You may even want to test if the device is touch based and provide a completely different experience for those users instead of trying to match hover.
Here's a media query for touch devices. #media (any-hover: none) { ... }
More info from CSS-Tricks and a good overview of what's possible in 2018.
I have a button and it renders weird in Firefox (I'm testing various versions, but I've see it in all of it). For more details, I use Normalize.css.
After several tests, the only difference between the PC with the issue and the PC with the correct behaviour is the graphic card.
Also, the issue differs depending the page you're seeing (the button is in various pages).
Here you can see a few screenshots in different PCs:
I have made a testcase in jsFiddle: http://jsfiddle.net/5R2NL/1/
Here's the HTML:
<div class="botonVerdeenlace">
<a title="Title" href="#">I feel like a button</a>
</div>
And the relevant CSS:
body{font-size:68.75%}
.botonVerdeenlace {
background: url("http://i.imgur.com/lk4ZJxQ.png") no-repeat scroll left center rgba(0, 0, 0, 0);
display: inline-block;
font-weight: normal;
margin: 0;
padding: 8px 2px 7px 29px;
}
.botonVerdeenlace a, .botonVerdeenlace a:visited {
background: url("http://i.imgur.com/2IgIR37.png") no-repeat scroll right center rgba(0, 0, 0, 0);
border: medium none;
color: #FFFFFF !important;
font-family: Arial,sans-serif;
font-size: 1.1em;
font-weight: normal;
margin: 0;
padding: 8px 1em 7px 7px;
text-align: center;
text-decoration: none;
}
What is causing that issue? It's certanly the video-card?
Is there any way to fix this issue without screw the design for other
users?
EDIT: I try the suggestion from Nico O, and the hardware acceleration doesn't seems to have any influence in the rendering.
EDIT2: Use css3 is not an option, because there are A LOT of buttons in the web. If this is the only solution the client will prefer to leave it "bad".
Maybe it's "Hardware Acceleration (GPU Rendering)" fault. You can disable this on options and test again but you are better served using CSS3.
But my client wants IE7: declare on CSS your normal button that works on IE7 than make a media query that works for any resolution with your CSS3 button, that way the button still nice on IE7 and works pretty well on firefox.
I'm working on a project to upgrade a system to use the button tag rather than regular submit buttons. For the formatting of the buttons, I have the following CSS classes:
button::-moz-focus-inner {
border: none; /* overrides extra padding in Firefox */
}
button {
background: transparent url('images/greenrightbutton.png') no-repeat scroll top right;
color: #FFFFFF;
display: block;
font: normal 12px arial, sans-serif;
height: 25px;
padding-right: 8px; /* sliding doors padding */
padding-top: 0px;
padding-bottom: 0px;
padding-left: 0px;
margin: 0px;
text-decoration: none;
border: 0px;
overflow: visible;
}
#loginbox button {
float: right;
}
button span {
background: transparent url('images/greenleftbutton.png') no-repeat top left;
display: block;
line-height: 18px;
padding: 4px 5px 5px 12px;
margin: 0px;
border: 0px;
}
They work absolutely perfectly in every browser except IE8.
In IE8, the buttons work in most places, but then I find a page where the two background images don't quite line up and no amount of tweaking padding, line spacing etc fixes it.
Does anyone know why this might be the case?
Demo page: http://test6.placement.co.uk/demo/test.asp
---Update---
After some fairly extensive testing and trying things, I've now got a pretty fair idea of what's causing the problem in page 1, but no idea how to fix it, while another page with the same issue has a completely different cause (which I haven't found) but where I HAVE stumbled on a fix...
The problem on the first page appears to relate to a ul entered further up the page. Take that out and everything behaves - unfortunately, that's not an option as the ul is part of user-entered content, so I'm scratching my head about that. Particularly given...
Page 2 has no uls to cause an issue, but randomly sticking two break tags in just before my button code resolves the problem.
Naturally, THAT fix doesn't work on page 1.
I'm just about ready to give in and find some alternative way of rendering these buttons, because whatever the actual problem is, it's clearly so deep in either my CSS or my basic HTML that I'm probably never going to find it.
I don't see any difference between IE8 and other browser. Could you pleas mention bit more clear what you want to do?
I'm trying to style my form buttons and I'm experiencing a problem in Firefox that I can't get to the bottom of...
I want to style certain <a />s and <input type="submit" />s to look the same (I have a button background image, using a sliding-doors technique to apply a hover effect.)
This all works great, except in Firefox, the input submit text is slightly lower down than it should be. IE and Safari/Chrome work fine.
(source: muonlab.com)
Anyone got any ideas?
Thanks
<div class="buttons">
« Back
<input type="submit" class="button btn-large-green" value="Save changes" />
</div>
.button
{
cursor: pointer;
border: 0;
background-color: #fff;
color: #fff;
font-size: 1.4em;
font-weight: bold;
outline: 0;
font-family: Arial, Verdana, Sans-Serif;
}
a.button
{
display: block;
float: left;
text-align: center;
text-decoration: none;
padding: 5px 0 0 0;
height: 22px;
margin-right: 1em;
}
.btn-small-grey
{
height: 27px;
width: 96px;
background-position: 0 -81px;
background-image: url(/assets/images/buttons/buttons-small.gif);
}
.btn-large-green
{
height: 27px;
width: 175px;
background-position: 0px -54px;
background-image: url(/assets/images/buttons/buttons-large.gif);
}
I found this post because I had resolved this problem a few months ago and when I ran into it again today, I couldn't remember what I'd done. Nice. After poring over my css I finally located the "fix". I can't take credit because I found it on the web somewhere, but hopefully it will be as useful to you as it has been for me:
input::-moz-focus-inner /*Remove button padding in FF*/
{
border: 0;
padding: 0;
}
I hope this helps.
I have same problem every time I need to style form buttons. Sorry, quite busy at the moment so only brief description how I usually fix it.
In FF Text is usually a bit lower, exactly like on the image you attached and so then I simply apply "padding-bottom" on the button itself. It moves the text on the button number of pixels up.
The problem is it also moves text in IE and now IE looks a bit off. To fix that I apply "line-height" to the same button with exactly same value as the height of the button. That makes IE to ignore padding completely and positions the text right in the middle. Below is sample HTML code:
<input type="submit" value="SEARCH" class="search"/>
and CSS:
.search
{
background: transparent url(../images/sprites.gif) no-repeat -310px 0; /* some button image */
height: 29px;
width: 104px;
border: 0;
/* centering text on button */
line-height: 29px; /* FF will ignore this but works for IE. This value should be same as value of the height property above */
padding-bottom: 2px; /* IE will ignore but works for FF */
}
Sorry I didn't applied it directly to your code but I'm a bit busy at the moment, hope you got the idea and it helps though.
ps. just checked in IE8 and all above moves text few pixels up. So it means more (endless?) mocking around with padding top/bottom.. I lost my patience now though and I think I'll be putting all this in separate stylesheet from now on that is until I find some fairly easy and universal solution for all this
Inputs are formatted not following the W3 box model convention in different browsers, you might want to include:
input /*Content follows box model*/
{
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box;
height:24px;
}
Also include for firefox (which Shelly pointed out):
input::-moz-focus-inner /*Remove button padding in FF*/
{
border: 0;
padding: 0;
}
Otherwise you could use button
I collected all these solutions from various sources, they deserve the credit
I had the same problem and I've solved (only for FF and Safari) by fixing the width but not the height and playing with the values: padding (top and bottom), line-height and if needed setting the vertical-align to middle. However all it's more easy to do if you set all the values (even the font size) in pixel.
EDIT: I think that there isn't a cross-browser solution, because the problem is due to the text rendering of the browsers. To solve completely the problem you could draw a background img with text and apply that image to the link or the button.
Even if with this solution you lose in accessibility.
Alternatively you can use conditional CSS statements to improve the layout for each browser.
You could also consider replacing the the button with a different element altogether. The anchor element works perfectly. Just add a 'submit' function to it's 'onClick' event and you'll be good to go. I think this is a better (and simpler) cross browser solution.