The website lacks accessibility features such as a text size swapper, but the contrast swapper is not functioning properly

As I embark on my first website project that requires accessibility controls, I find myself in need of the ability to adjust text size and contrast settings. Specifically, I want to offer options for small, default, and large text sizes as well as normal, yellow on black, and black on yellow contrast settings. While I consider myself an average front-end developer, I don't often work with JavaScript or jQuery.

To address this requirement, I plan to define classes in the HTML "body" element to handle each case.

In pursuit of this goal, I have developed the following jQuery script:

// Accessibility 
// Check for cookies and set body class accordingly
if($.cookie("bodyclass-text")) {
      $("body").addClass($.cookie("bodyclass-text"));
    }
if($.cookie("bodyclass-contrast")) {
      $("body").addClass($.cookie("bodyclass-contrast"));
    }
// initialize the jquery code
 $(document).ready(function(){
  // add or remove classes to body as appropriate
  // return false keeps the browser from following the link's '#' target

  // Text size
  $("#defaultText").click(function(){
    $("body").removeClass("small-text");
    $("body").removeClass("large-text");
    $.cookie("bodyclass-text", null);
    return false;
  });
  $("#smallText").click(function(){
    $("body").removeClass("large-text");
    $("body").addClass("small-text");
    $.cookie("bodyclass-text", "small-text", { expires: 365, path: '/' });
    return false;
  });
  $("#largeText").click(function(){
    $("body").removeClass("small-text");
    $("body").addClass("large-text");
    $.cookie("bodyclass-text", "large-text", { expires: 365, path: '/' });
    return false;
  });

  // Contrast
  $("#defaultContrast").click(function(){
    $("body").removeClass("black-on-yellow");
    $("body").removeClass("yellow-on-black");
    $.cookie("bodyclass-contrast", null);
    return false;
  });
  $("#yellowOnBlack").click(function(){
    $("body").removeClass("black-on-yellow");
    $("body").addClass("yellow-on-black");
    $.cookie("bodyclass-contrast", "yellow-on-black", { expires: 365, path: '/' });
    return false;
  });
  $("#blackOnYellow").click(function(){
    $("body").removeClass("yellow-on-black");
    $("body").addClass("black-on-yellow");
    $.cookie("bodyclass-contrast", "black-on-yellow", { expires: 365, path: '/' });
    return false;
  });
});

While I have succeeded in implementing the text size adjustments, I am facing challenges with the contrast settings. It seems like a CSS issue because when I inspect the page using Firebug, the body classes are being correctly applied but the yellow on black and black on yellow contrasts are not working as expected. I even attempted to include larger font sizes in the CSS, which worked for adjusting the text size.

Here is an excerpt of my relevant CSS styles:

/* Accessibility options */
body {
    font-size: 1em;
    color: #777;
    background: #fff;
}

body.yellow-on-black !important{
    color: yellow;
    background: black;
    font-size: 3em;
}

body.black-on-yellow !important{
    color: black;
    background: yellow;
    font-size: 3em;
}


body.small-text {
  font-size: 0.8em;
}

body.large-text {
  font-size: 1.4em;
}

For reference, here is a snippet of my HTML structure:

<div id="defaultText"><a>Normal text</a></div>
<div id="smallText"><a>Smaller text</a></div>
<div id="largeText"><a>Larger text</a></div>
<p>
<div id="defaultContrast"><a>Default Contrast</a></div>
<div id="yellowOnBlack"><a>Yellow on Black</a></div>
<div id="blackOnYellow"><a>Black on Yellow</a></div>

If anyone has suggestions on how to resolve this issue, please feel free to contribute your insights.

You can access the test web page at this URL:

The accessibility options can be found at the bottom of the right column on the webpage.

Thank you in advance for your assistance!

Answer №1

Two instances of !important are incorrectly used in the CSS code. Only individual properties can have !important, so these rules will be excluded. It is recommended to remove !important from

body.yellow-on-black !important{

and

body.black-on-yellow !important{

and consider adding !important only to specific properties if absolutely necessary. This should generally be avoided unless you need to override existing CSS with !important that cannot be modified.

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

Replace existing styled-component CSS properties with custom ones

One of my components includes a CheckBox and Label element. I want to adjust the spacing around the label when it's used inside the CheckBox. Can this be achieved with styled()? Debugging Info The issue seems to be that the className prop is not b ...

Concealing my menu with overflow-x: hidden on the body is not an option

Despite setting overflow-x: hidden on the body element, I'm still experiencing horizontal scrolling and can't seem to find a solution. I've searched online for solutions without success. That's why I'm reaching out here in hopes o ...

What is the process for utilizing Sass in Vue CLI rather than node-sass (which is the default for sass-loader)?

I found a solution, but it's specifically for Nuxt.js and I'm using the Vue CLI. Is there any way to use dart sass instead of node-sass (default for sass-loader) in Nuxt.js? While the Vue CLI official documentation displays an example utilizing ...

What is the best way to increase the spacing between inline-block elements?

Just to clarify, I am not looking to delete space between inline-block elements - rather, I want to insert it. My goal is to create a grid of menu items that can accommodate 2, 3, or 4 items per row, and I hope to achieve this using media queries. Is the ...

Having trouble spinning the picture using Reel in Reactjs

I have recently started learning React and I am attempting to use jQuery reel to rotate a list of images by 360 degrees. While I have successfully implemented this using purely jQuery, I now want to migrate it over to Reactjs. The issue arises when trying ...

Create a dynamic menu dropdown with absolute positioning using React

I recently made the transition to React and now I am in the process of converting my old vanillaJS website into ReactJS. One issue I am facing is with a button that is supposed to trigger the opening of a dropdown menu. <button type="button&qu ...

Chrome's spinner fails to appear when performing a synchronous ajax request in IE9

While implementing an ajax request, I want my users to see a spinner for visual feedback. Surprisingly, the spinner works flawlessly on Firefox 13, but fails to function on Chrome and IE9 even though the ajax request takes approximately 1.2 seconds to comp ...

Velocity 1.5 causing issues with jQuery compatibility

I am encountering issues with incorporating jQuery into my code within a velocity template. Despite using velocity 1.5, the jQuery functionality does not seem to be working properly. Could you please suggest a solution? <script src="/CostTrackerReport ...

Adjust the height of the div element to match the screen height with AngularJS controller

Can someone please assist me in resolving this issue? I'm currently working on a div element that displays data (positioned on the left side of the screen). I want to add a scrollbar exclusively to this div. I managed to achieve this by using the fol ...

Is there a way to bypass the initial result when using document.querySelectorAll?

this is my own unique html content <div class="content-body"> <table style="text-align:center;" class="table table-bordered"> <tbody> <tr> <th>Text Line</th> </tr> <tr> <td> ...

The battle between Typography and HTML formatting elements

When it comes to choosing between the <Typography/> tag and normal HTML tags like <p>, I find myself in a state of ambiguity. <Box className={someClassName}> <Typography>{someVariableName}</Typography> </Box> or <p ...

Centering an item within a dropdown navigation bar

Hey there, I'm currently facing a challenge with centering an image within my dropdown bar. My goal is to have it float to the right and be centered, but it's not cooperating. Here's the code snippet I'm working with: <!DOCTYPE htm ...

How to create a custom CSS style to make Bootstrap 4 modal slide in from the bottom

Back in the days of Bootstrap 3, this was the trick: .modal.fade .modal-dialog { -webkit-transform: translate3d(0, -25%, 0); transform: translate3d(0, -25%, 0); } Another approach that could have been used: .modal.fade .modal-dialog { transfor ...

Steps to display images within a div from a specific directory

Recently, I have encountered a challenge that involves retrieving images from a specific directory, regardless of the number of images present, and then displaying them in a div using an unordered list. I attempted the following code snippet, but unfortuna ...

Having difficulty grasping the concept of toggleClass and jQuery selectors

I am struggling to understand the getLiveSearchUsers function in my JS file. Could someone please help me? I don't quite grasp what selector[0] is and what toggleClass is doing here. $.post("includes/handlers/ajax_search.php", {query:value, userLogge ...

Tips for resizing a background image horizontally without changing its height

Having a background image that is taller than the page and setting it as the background for the wrapper has caused some issues. Resizing the window results in a large amount of white space under the background image due to the fixed height of the wrapper. ...

The alignment of the background images is off

I am attempting to give a container a background image and then create two div tags using the col-md-6 classes from Bootstrap. The main div's background image is of grass texture, while the two inner divs have a skeleton of a football court as their b ...

What might be causing the issue of a click handler not registering during the initial page load when using Enquire.js

I am experimenting with different effects on various breakpoints. My main goal is to achieve the following behavior: when a category is clicked from the list within 720px, the category list should fade out while the data is revealed in its place. However, ...

Aligning a bootstrap button group at the center of a container

Looking for suggestions on how to center a Bootstrap button group (btn-group) within an element? For instance, consider the following structure: <div id='toolbar'> <div class="btn-group"> <button type="button" class="b ...

The flex grow animation fails to activate when the Bootstrap 4 style sheet is added

Trying to implement transitions with flex grow has been a challenge. It works smoothly without any issues, but as soon as I add the bootstrap 4 style sheet, the transitions stop working. I haven't even started using the bootstrap 4 classes yet, it&apo ...