Show only the initial character for glyph fonts (accessible format)

I'm working with a glyph font and looking to create a specific visual effect:

Here's the code I have so far:

<div class="ico linkedin">linkedin</div>
        
.ico {border-radius:10em; background:black; color:white}
.linkedin {visibility:hidden;}
.linkedin:first-letter {
    font-family:'JustVector'; 
    font-size:900%; 
    text-indent:1em; 
    visibility:visible
 }

This approach works in Chrome, but turns out it doesn't work in Firefox or Internet Explorer 9. It also raises accessibility concerns as screen readers like JAWS don’t acknowledge the elements with hidden or display:none.

In an attempt to address this issue, I experimented with:

.linkedin {position:absolute; left:-5em}
.linkedin:first-letter {/*etc*/ position:absolute; left:6em}

Unfortunately, this solution didn’t yield the desired result. Is there a proper and accessible way to achieve this effect?

Answer №1

To ensure accessibility when using icons, it is best to utilize img elements with descriptive alt attributes, like this:

<img src=smiley.gif alt="Just kidding!">

Icon fonts, often referred to as “glyph fonts,” present inherent accessibility challenges. Attempting to manipulate letters into appearing as icons through CSS tricks results in incorrect information if CSS is disabled. Similarly, using empty content elements with CSS-generated content leads to no information when the visual aspect of CSS is turned off.

Answer №2

Utilizing icon fonts in an accessible manner can be challenging at the moment. To tackle this issue, consider following this approach:

Start by enclosing the text within a span element for hiding purposes. Additionally, include another span element for the icon.

<div class="ico">
    <span aria-hidden="true" class="linkedin"></span>
    <span class="hide">linkedin</span>
</div>

Note the inclusion of aria-hidden="true" in the icon span to prevent screen readers from reading out the symbol used for rendering.

Once the text is hidden to accommodate screen readers, you can proceed to apply the icon using the before pseudo-element selector.

.linkedin:before {
    font-family: 'JustVector'; 
    content: 'l';
}

.hide{
    position: absolute;
    top: -9999px;
    left: -9999px;
}

Answer №3

Thank you for providing answers that have sparked some questions in my mind on how to handle this situation.

In the end, I decided to go with the simpler option. It is accessible, more semantic, works even without CSS on the page, and can be easily printed.

I made sure to separate the first letter (the icon) from the surrounding text with a margin, and kept the layer with overflow:hidden;. Then, I adjusted the margin and line-height to properly center the character/icon inside the circle.

Here is the final code:

.ico {background:black; border-radius:10em; height:5em; overflow:hidden; position:relative; width:5em; color:white;}
.linkedin:first-letter {font-family:'JustVector'; font-size:400%; line-height: 1.3em; margin-left:0.2em; margin-right:1em;}

With this solution, screen readers will read "linkedin" while visually displaying only the icon to provide enough information for other users.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for avoiding accidental unit conversion in jQuery

Imagine having the following code: var $element = $('<div/>'); $element.css("margin-left", "2cm"); console.log($element.css("margin-left")); When tested in Chrome, it doesn't return anything, but Firefox shows "75.5833px". Any sugges ...

Issue Encountered While Loading CSS using Webpack and Babel

I am currently working on a SSR React App using Webpack3 and Babel6. However, when I launch the server, it is not able to locate any css file (Error: Cannot find module './file.css'). Here is an overview of my current folder structure: src/ | ...

Display a different div when hovering over an li element

Within my HTML, I have two div elements. The first div is filled with Menu items represented by li elements, while the second div contains submenus. My desired functionality involves displaying the submenu when hovering over a menu item's li element u ...

Ensure that the display is set to block to stack the input elements on top of each other

I am attempting to grasp the functionality of CSS display property and experimented with this basic HTML code: <div> <form className="container" action=""> <input name="fName" placeholder="First Name" type="text" value={props.fNam ...

Design cards in a particular sequence using either bootstrap or CSS

I am currently developing a blog website and I need assistance with arranging the cards in this specific order: https://i.sstatic.net/Ffpcb.png Despite my efforts using Bootstrap, I am unable to achieve the desired layout. Here is the code I have so far: ...

"Maximizing TableView Cell Height to Utilize the Entire Screen

After reading the tutorial on Appcelerator: Using JSON to Build a Twitter Client, I decided to create my own application to communicate with a Jetty server running some Spring code. My application makes a GET HTTP request that returns contacts in JSON form ...

What is the best way to elegantly finish a live CSS animation when hovering?

Currently, I am working on a planet orbit code where I want to enhance the animation speed upon hover. The goal is for the animation to complete one final cycle at the new speed and then come to a stop. I have been successful in increasing the speed on hov ...

Steps for adjusting the position of this div in relation to the main container

Apologies in advance for my lack of HTML skills. I am struggling with a page layout issue. I have a website at . When the window is resized, the ads div on the right side overlaps the main container. What I would like to achieve is to make this ads div re ...

In ReactJs, you can use break tags to format a lengthy string and also apply color to certain words within the string

When working with ReactJs, my objective is to format a lengthy string by inserting <br/>. I was able to achieve this using a JavaScript function as shown below: The long string in question: export const fadeAnimation = { \n initial: {opacity: ...

A step-by-step guide on extracting the image source from a targeted element

Here is a snippet of my HTML code containing multiple items: <ul class="catalog"> <li class="catalog_item catalog_item--default-view"> <div class="catalog_item_image"> <img src="/img/01.png" alt="model01" class="catalog_it ...

Issue with functionality of inline list menu

Having trouble with a JQ drop down menu and suspect it's an HTML/CSS issue. Spent hours tweaking it, but still not working as expected. Looking to understand the correct approach rather than just getting it to function. The slidetoggle feature is mess ...

What is the best way to incorporate vertical lines into a set of progress bars?

I want to create progress bars with vertical lines representing specific steps within the progression. While I can display progress bars, I am unsure how to incorporate these vertical lines. Does anyone have any suggestions or ideas on how to achieve this? ...

Is it better to use one large CSS file for Angular 2 or opt for separate files per component

When working with Angular 2, the choice of how to style your application is an important decision. Should you create one large minified .css file using a task runner like Gulp, or use Angular 2's styleUrls: ['myfile.css'] for each component? ...

What is the best way to ensure that my Material UI container occupies the entire width and height of the

Struggling to fit my content within a Material UI container in a React project, but it's creating odd margins. Check out the current look: https://i.stack.imgur.com/TaQs2.png Here's how I want it to display with full width: https://i.stack.imgur ...

Organize Radio Selectors

My intention was to align the radio buttons as shown in the image below: https://i.stack.imgur.com/oPTjD.jpg However, the final result looked like this https://i.stack.imgur.com/Mixga.jpg Below is the code for your reference HTML <div class="form ...

Conceal series of images with a click; reveal them again once completed

I'm working on a layout featuring overlapping images and I'm looking to create a hide-and-seek effect where the images are hidden one by one when clicked, and then shown in reverse order until all of them are visible again – essentially creatin ...

What is the best way to switch a single class using jQuery without impacting other elements with the same class

I'm in the process of implementing a commenting system similar to Reddit on my website. Each comment is equipped with a small button in the top right corner that allows users to collapse the comment. To achieve the collapsing effect, I am utilizing j ...

Ensure the column breaks before the element without disrupting the wrapper in CSS

My objective is to always initiate a line break before a specific element, in this case, the h2 tag: https://i.sstatic.net/fy80H.png https://jsfiddle.net/hv0sm40o/3/ html <div class="columns"> <h2>Jelly pastry chocolate cake pastry</h2&g ...

Click to solve the equation

I want to build a basic HTML page with three input variables (A,B,C). After the user inputs these values, they will click "calculate", and JavaScript will execute the following equations: ((A + B)/2) * 3 = X and (C * 2) = Y The results will be displaye ...

Text area featuring unique border design, with border color change upon focus?

Currently, I have a text area with borders that are designed in a unique way. However, I am looking to change the border color when the user focuses on the text area. Do you have any suggestions on how I can achieve this effect without affecting the curre ...