I made the following card design to show on a news page:
To make this accessible I want the h2 heading to be in front of the image in HTML like:
<div class='news'>
<h2>Title</h2>
<img alt="temporary placeholder image" src="https://via.placeholder.com/400x300.png">
<small class="news--published">6-3-2020 1:27:20</small>
<div class="body">
<p>Lorem ipsum dolor.</p>
</div>
<a aria-label="Read more about {{node.title}}" href="/url">Read more<span aria-hidden="true" class="icon icon-arrow"></span></a>
</div>
What is the best solution to do this? Is there a way to create this design with css, for example by using flexbox or grid, from the html mentioned above? Or is it possible to change the html for example by wrapping this in an <article> wrapper and change the order like:
front of the image in HTML like:
<article class='news'>
<div class="content image">
<img alt="temporary placeholder image" src="https://via.placeholder.com/400x300.png">
</div>
<div class="content text">
<h2>Title</h2>
<small class="news--published">6-3-2020 1:27:20</small>
<div class="body">
<p>Lorem ipsum dolor.</p>
</div>
<a aria-label="Read more about {{node.title}}" href="/url">Read more<span aria-hidden="true" class="icon icon-arrow"></span></a>
</div>
</article>
The question to ask yourself is "does the image add any useful information at this point". At that point you have two options:
The image does not add anything
The answer is probably no, the image does not add anything of value in a list of articles.
Although you will often see me advocating for as similar an experience as possible for people with disabilities, I also advocate for a great user experience.
It is not a great experience having a load of images read out as part of a list of articles as it just slows down the experience. Additionally article thumbnails are often abstract (offering no useful information) and repeated at the top of the actual page (redundant).
As such my advice is to hide the image entirely. You can do this simply by changing your alt attribute to an empty string. An empty string, not a null string
So <img alt="" src... is fine, <img alt src... is not.
For completeness I would also add aria-hidden="true" to the image, although this is redundant it is useful for people when they are looking through your code for empty alt attributes to see this should be hidden and it is not a mistake / missing alt attribute.
<article class='news'>
<div class="content image">
<img alt="" aria-hidden="true" src="https://via.placeholder.com/400x300.png">
</div>
<div class="content text">
<h2>Title</h2>
<small class="news--published">6-3-2020 1:27:20</small>
<div class="body">
<p>Lorem ipsum dolor.</p>
</div>
<a aria-label="Read more about {{node.title}}" href="/url">Read more<span aria-hidden="true" class="icon icon-arrow"></span></a>
</div>
</article>
The image is really important
No problem, that is all part of making a site accessible. Using your best judgement.
For this we can visually change the order so that the DOM order is correct for screen reader users.
People often think this is a no-no as they have read "logical tab order / focus order" and think all items on the page have to be in DOM order.
They do not, logical focus order applies to controls and interactive elements.
Changing the visual order can be achieved simply using flex and row-reverse as per the example below. Or you could use old-school float left and right.
That decision is down to what browsers you support.
By changing the DOM order screen reader users get the important information first and still have the option of accessing the image.
.news {
display: flex;
flex-direction: row-reverse;
}
.content.text{
flex: 2;
padding: 20px;
}
.content.image{
flex: 1;
}
<article class='news'>
<div class="content text">
<h2>Title</h2>
<small class="news--published">6-3-2020 1:27:20</small>
<div class="body">
<p>Lorem ipsum dolor.</p>
</div>
<a aria-label="Read more about {{node.title}}" href="/url">Read more<span aria-hidden="true" class="icon icon-arrow"></span></a>
</div>
<div class="content image">
<img alt="temporary placeholder image" src="https://via.placeholder.com/400x300.png">
</div>
</article>
Extra based on comments
Obviously there are other improvements that can be made to the HTML.
I wasn't going to go into them but #Shannon Young's comment about associating the article with the heading is a good one to include.
What they were suggesting is to do the following:
<article aria-labelledby="articleHeading1"/>
<h2 id="articleHeading1">Title</h2>
This means if a screen reader user is navigating by sections the section will be read as "article, Title" (or similar depending on screen reader).
They also made a comment about using the <time> element etc. That is something for you to research yourself.
Related
We want to add support for people with disabilities. So I read about it over the internet but did not get too much from there. I am not understanding when to use aria and when to use role attributes.
I have simple HTML with 3 columns. I have used role attributes in that and wanted to know what more can be done on this HTML for accessibility. Like if we want to use aria-labelledby and aria-describedby.
<div class="container">
<div class="partners clearfix">
<h2 role="My Content Heading">My Content Heading</h2>
<div class="row" role="partner type">
<div class="col-xs-12 col-sm-4">
<div class="partner__list text-center">
<div class="center">
<i class="service"></i>
<h2>Partner 1</h2>
<p>Partner 1 Description</p>
<div class="button-pos">
Learn More
</div>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="partner__list text-center">
<div class="center">
<i class="tech"></i>
<h2>Partner 2</h2>
<p>Partner 2 Description</p>
<div class="button-pos">
Learn More
</div>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-4">
<div class="partner__list text-center">
<div class="center">
<i class="content"></i>
<h2 class="text-lg text-black text-ellipsis">Partner 3</h2>
<p>Partner 3 Description</p>
<div class="button-pos">
Learn More
</div>
</div>
</div>
</div>
</div>
</div>
</div>
Two things immediately stand out that could be improved:
1) You're using what appears to be a font-icon that seems to have meaning that has no text alternative:
<i class="service"></i>
You can provide this with an aria-label property. In addition, I'd recommend using a span instead if <1>:
<span class="service" aria-label="service"></span>
2) The text in your links is repetitive and has no specific information about the link destination. Screen reader users often scan the links to get a feel for the page content and without the surrounding content this will be less useful that it could be ("learn more", "learn more", "learn more")
Learn More
I'd recommend adding specific information in the linked text rather than the generic "learn more":
Learn More about partner 1
Modified markup for one section:
<div class="container">
<div class="partners clearfix">
<h2 role="My Content Heading">My Content Heading</h2>
<div class="row" role="partner type">
<div class="col-xs-12 col-sm-4">
<div class="partner__list text-center">
<div class="center">
<span class="service" aria-label="service"></span>
<h2>Partner 1</h2>
<p>Partner 1 Description</p>
<div class="button-pos">
Learn More about Partner 1
</div>
</div>
</div>
</div>
</div>
</div>
</div>
This code snippet is already accessible. Most plain HTML doesn't need additional ARIA support. Text-to-speech software will just read through it in order, and keyboards can Tab to the links and press Enter to click them. ARIA is for when you have interactive widgets like tabs or calendars.
Role attributes are part of the ARIA specification. You don't need to make up values to describe your content, they should only be used from this list if they apply to what you're making.
You might also find this introduction to web accessibility article and the other resources on that website useful in learning more about it.
As stringy already pointed out, the code is already accessible. If you aren't using JavaScript to create UI elements, there is usually no need for WAI-ARIA roles or attributes.
I have just two comments about your code:
Why do you use a div around Learn More instead of a p? Screen readers can move between paragraphs, but div elements are meaningless, as far as I know.
If the partner descriptions are meant to look like a table, and especially if there will be regular row or column headers, you should use table markup instead of CSS-styled div elements. Regular table markup makes sense to a screen reader; styling div elements to look like a table results in a meaningless (i.e. from the point of view of a browser or a screen reader) code jumble.
Can i put logo nested with anchor inside the <figure> ? Is it right?
Here is the code
<header>
<div class="row">
<figure class="col-sm-5"> <img src="images/logo.gif" class="img-responsive" height="60" width="330" alt="site-logo"> </figure>
<div class="col-sm-7">
<div class="well">
<div class="row">
<div class="col-xs-9"><nav></nav></div>
<figure class="col-xs-3"> <img src="images/helpline.gif" class="img-responsive" height="60" width="120" alt="helpline-image"> </figure>
<div class="clearfix"></div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
</header>
Yes you can.
The HTML <figure> element represents self-contained content, frequently with a caption (<figcaption>), and is typically referenced as a single unit. While it is related to the main flow, its position is independent of the main flow. Usually this is an image, an illustration, a diagram, a code snippet, or a schema that is referenced in the main text, but that can be moved to another page or to an appendix without affecting the main flow.
Reference : MDN
I know this is old, but please do not place your logo in an <h2>; it is not the place for it and can mess up your accessibility, your dom heading structure, and your SEO performance. Doing something because you can, does not make it the right solution below are some links about how to use heading tags. If you want it to look like an <h2>, then style it in your CSS.
W3 Schools
MDN
SEO and Headers Article
For better SEO, put your logo inside H2 tag.
<h2>
<a href="#">
<img src="logo.gif" alt="stackoverflow-logo"/>
</a>
</h2>
Give proper name for alternate text tag alt, instead of site logo, give your companyname-logo
I have got some elements on my page, they should all be styled the same except for every other one, where I just want to change some styling.
Here is the CSS which I was hoping would select the div inside the stack of different elements:
.stagger_reviews[class=inner]:nth-child(2n+2) {
background-color:#003;
}
Here is the HTML:
<div class="stagger_reviews">
<!-- Later use PHP to load reviews, CSS should switch the images from left to right -->
<article class="container box style1">
<a style="background-image:url(images/blank-user.jpg); " href="#" class="image fit"></a>
<div class="inner">
<header>
<h2>Martyn Ball</h2>
</header>
<p>
I found this service on a Google Search, didn't expect it to be so great!
</p>
</div>
</article>
<article class="container box style1">
<a style="background-image:url(images/blank-user.jpg); " href="#" class="image fit"></a>
<div class="inner">
<header>
<h2>Martyn Ball</h2>
</header>
<p>
I found this service on a Google Search, didn't expect it to be so great!
</p>
</div>
</article>
</div>
As you can see I just want to adjust the one div inside each article which has the class name inner. And maybe some other elements as well but once I have this working I can do that.
The style isn't being applied to the second inner div, I have made about 4 copies of the article and none are being changed.
Here is the solution, I put the nth-child in the wrong place.
.stagger_reviews > article:nth-child(2n+2) div[class=inner]
As asked in the title, I am creating a website by using bootstrap v3.3.2.
The first question is that I am using the grid system to align the caption to the right of the thumbnail as shown below:
<div class="container">
<div class="thumbnail">
<div class="row">
<div class="col-md-6">
<a href="#">
<img class="img-responsive" src="images/pic.jpg">
</a>
</div>
<div class="col-md-6">
<div class="caption">
<h2>Title</h2>
<hr>
<p>A design specification provides explicit information about the requirements for a product and how the product is to be put together. It is the most traditional kind of specification, having been used historically in public contracting for buildings, highways, and other public works, and represents the kind of thinking in which architects and engineers have been trained.</p>
<hr>
<p class="caption-footer">
<span class="glyphicon glyphicon-heart"></span> Like it
<span class="glyphicon glyphicon-share"></span> Share it
</p>
</div>
</div>
</div>
</div>
</div>
Which turns out to be something like this:
As noticed, there is a large margin to the left of the image, which is not ideal. And when I resize the screen, it became more undesirable, with large margin to both side as shown below:
I think this may caused by the grid system since the col-md-6 has a fixed width. However I do not know how to fixe this.
The second question is that I try to align the two buttons to the bottom of the caption by adding a new class called caption-footer. However, this does not work.
Below is my CSS file for class caption-footer and how it turns out to be:
caption-footer{
position: absolute;
bottom:0;
left: 0;
}
I have checked quite a few links here (like: link1 link2). But none of them seems to work for my case.
Thanks in advance for any help!
One thing you can do simply place caption under col-md-12 div and buttons under another col-md-12 div.
<div class="container">
<div class="row">
<div class="col-md-6">
<a href="pulpitrock.jpg" class="thumbnail">
<p>Pulpit Rock: A famous tourist attraction in Forsand, Ryfylke, Norway.</p>
<img src="pulpitrock.jpg" alt="Pulpit Rock" width="284" height="213">
</a>
</div>
<div class="col-md-6">
<div class="col-md-12">
A design specification provides explicit information about the requirements for a product and how the product is to be put together. It is the most traditional kind of specification, having been used historically in public contracting for buildings, highways, and other public works, and represents the kind of thinking in which architects and engineers have been trained.
</div>
<div class="col-md-12">
Download
Images
</div>
</div>
</div>
</div>
I know this is probably frowned upon, but a client wants live text wrapped in ONE tag....
So, here is my dilemma:
I have some code like this:
<a href="google.com">
<img src="img.jpg" style="float:left;">
<div style="float:right;">
<h3>Title</h3>
<p>Description</p>
</div>
<div style="clear:both;"></div>
</a>
I styled the to be display:block.
This method works great in FF5, IE = not all content is clickable, in this example only the image is clickable. Chrome = works. Safari = works.
If you have a different method you might suggest please offer it.
Thanks in advance!
Try setting the link style like this:
<a style="display: block; position: relative;" ><div/></a>
One suggestion is not to use block level elements in an inline element. It won't always render properly (beyond being semantically incorrect). Try removing the floats and using spans to style the part that you want to be an H3 and p.
<a href="google.com">
<img src="img.jpg" style="float:left;">
<span class='title'>Title</span>
<span class='desc'>Description</span>
</a>
This is completely against the html specification since <a> elements can only contain inline elements and <div> is a block element. So, it's no surprise that it doesn't work in Internet Explorer. In fact, it probably doesn't work in a number of other browsers, and even in those where it does work, there's no guarantee that it will continue to work.
The only workaround I can think of involves JavaScript, like this:
<div onClick="javascript:window.open('google.com')">
<img src="img.jpg" style="float:left;">
<div style="float:right;">
<h3>Title</h3>
<p>Description</p>
</div>
<div style="clear:both;"></div>
</div>
However, that will break support for users that don't have JavaScript, or have it disabled.
In HTML 4, block-level elements are not allowed in <a> tags so I would not expect it to work cross-browser.
A better solution may be to use a Javascript onclick event to send the user to the intended destination.
<div id="clickable_div" onclick="document.location.href='http://google.com'">
<img src="img.jpg" style="float:left;">
<div style="float:right;">
<h3>Title</h3>
<p>Description</p>
</div>
<div style="clear:both;"></div>
</div>
You could try making the <a> into a <div> and use javascript & css to make it look & work like a link
<div onclick="document.location.href='http://www.google.com'" style="cursor:pointer">
<img src="img.jpg" style="float:left;">
<div style="float:right;">
<h3>Title</h3>
<p>Description</p>
</div>
<div style="clear:both;"></div>
</div>