Highlighted top and bottom borders accenting a vertical list

I am working on a list that contains four items. Each item should have top and bottom borders set to 1px solid grey by default. There is a JavaScript rotator in place that adds a 'highlighted' class to the selected list element, which should have borders of 2px solid blue. Although I have managed to get the rotation functioning and the basic styling for unselected elements, I am facing an issue with applying a second class (infoHighlighted) using jQuery to override the borders. Additionally, I am struggling to figure out how to remove the grey bottom border from the previous element. This seems like it should be simple, but I am having trouble grasping it.

UPDATE - The highlighting problem has been solved thanks to HardyHarzen's help. My remaining challenge is to remove the lower border of the previous list element so that the highlight does not display the 1px lower grey border of the element above it.

.sideBox {
    width: 225px;
    float: right;

}

.sidebox ul {

    list-style: none;
    margin: 0;
    padding: 0;
    text-indent: 0;
}

.sidebox li {
    height:124px;
    margin: 0;
    padding: 0;
    border-bottom: 1px solid #666;
}


.sidebox li:first-child{
    height:123px;
    border-top: 1px solid #666;
    border-bottom: 1px solid #666;
}

.sidebox h4, .sidebox p
{
    margin: 0;
    color: #707070;
    padding:0;
    font-size: 25px;
}

.infoHighlighted {
    border-top: 2px solid #00A4E4;    
    border-bottom: 2px solid #00A4E4;    
}
.infoHighlighted h4 {
    color: #00A4E4;
    font-family: Georgia;
    font-size: 25px;
}
  <div class="sideBox">
                    <ul>
                        <li id="infoBox_0" class="infoHighlighted"><h4>Header Here</h4><p>One Sentence</p></li>
                        <li id="infoBox_1"><h4>Header Here</h4><p>One Sentence</p></li>
                        <li id="infoBox_2"><h4>Header Here</h4><p>One Sentence</p></li>
                        <li id="infoBox_3"><h4>Header Here</h4><p>One Sentence</p></li>
                    </ul>
               </div>

Answer №1

Understanding CSS specificity is key here! Remember, one class selector is less specific than a combination of class and element selectors. Try changing ".infohighlighted" to something like ".sidebox li.infohighlighted" to see if that resolves your basic highlighting issue.

Could you provide more details about what you're experiencing with the grey bottom border on the previous element?

On another note, watch out for case inconsistencies like sidebox vs sideBox in your code.

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

Alerting Users Before Navigating Away from an Angular Page

I am looking to implement a feature in my app that will display a warning message when attempting to close the tab, exit the page, or reload it. However, I am facing an issue where the warning message is displayed but the page still exits before I can resp ...

JavaScript error message stating that the setAttribute function is null

As a newcomer to JS, I am currently working on creating a task list webpage that allows users to submit projects and create task lists within each project with designated due dates. In order to generate unique ID tags for projects and tasks, I utilized UU ...

Troubleshooting an Issue with CSS Sliding Doors

I'm having trouble getting the right image to show on my website. The left side of the image is fine, but I can't figure out how to make the right one appear. As a HTML/CSS beginner, I'm still learning the basics. For more information, vis ...

Utilize AJAX and C# to seamlessly map JSON data onto an object

What is the best way to utilize JSON formatted data received from an AJAX request in C#? Check out this View with JQuery and AJAX: <script type="text/javascript"> $(function () { $("#btnGet").click(function () { var values = ...

What is the best way to include a string in formData when making an ajax request

Is there a way to include the id when sending formdata? I need help modifying my code for better understanding. $(document).ready(function() { $("#profile_photo_form").on('submit', (function(e) { e.preventDefault(); var id = $("#update ...

To ensure responsiveness in JavaScript, adjust the width to 100%

Recently, I came across this piece of code: <div style="text-align:center; max-width:500px; width:100%; margin:auto"> <script type="text/javascript" src="transition_example.js"></script></div> Here is the content of transition ...

Efficiently submitting a directory with jQuery's AJAX capabilities

I am attempting to send an ajax request in the following manner: $.ajax({ url: 'directory/file.php', type: 'POST', data: 'param1=' + param1 + '&param2=' + param2, ...

Issue with Flexbox Layout - Flipping Card

As a newcomer to web development, my first project is a fan-page dedicated to Metallica. Here's the link to my project on Github. I'm currently facing an issue with the flex-box layout in the "Discography" section of the page. You can view the ...

Send the form to the webpage and display various div elements based on the entered information

I have created a form that is designed to display one of four hidden divs on a page, depending on the input provided. Here is the form: <form> <input id="place" name="place" type="text"> <input name="datepicker" type="text" id="datepicker" ...

Leveraging the power of PHP and AJAX for seamless transmission and reception of JSON data through a

I am in the process of creating a basic form that consists of a single text field and a submit button. The goal is to have the entered value posted to a $.getJSON method upon clicking the button, which will then retrieve a JSON response and display it on t ...

Tips for automatically displaying user text based on its natural direction

Looking for a way to properly display user inputted text in Unicode based on its general direction, rather than defaulting to left-to-right. An issue arises when dealing with Arabic text as shown below, where the English word (4th) is split apart: اُر ...

PHP programming language for opening, editing, and saving HTML files

Trying to use PHP to open an HTML file, remove the content of a specific div (class Areas), and then save it. $dom = new DOMDocument; $dom->loadHTMLFile( "temp/page".$y.".xhtml" ); $xpath = new DOMXPath( $dom ); $pDivs = $xpath->query(".//div[@class ...

Issues with Codeigniter Ajax Post functionality

Hey everyone, I'm working on implementing a simple voting system for comments using jQuery Ajax to avoid page refreshing when someone likes or dislikes a comment. Here is the jQuery code I have so far: $(document).ready(function(){ $(".vote-btn" ...

Best practices for implementing dual ngFor directives within a single tr element?

Click here to view the page The image attached shows the view I want to iterate through two ngFor loops inside the tr tag. When using a div tag inside the tr, it's looping the button next to the tag instead of where I want it in the file table header ...

Tips on preserving CSS modifications made in Chrome Developer Tools Inspector to .vue file

Currently, I am in the process of setting up a new workflow where my goal is to streamline my work by using the Chrome DevTools Inspector to save any CSS changes directly to my .vue file. While the DevTools Workspaces feature can achieve this, it involves ...

Is there a way to modify Style Properties in JavaScript by targeting elements with a specific class name using document.getElementsByClassName("Class_Name")?

I am seeking a solution to change the background color of multiple div boxes with the class name "flex-items" using JavaScript. Below is my current code: function changeColor(){ document.getElementsByClassName("flex-items").style.backgroundColor = "bl ...

Comparison between using jQuery to append and execute a <script> tag versus using vanilla JavaScript

As I enhance my application, I've made the decision to embrace Bootstrap 5, which no longer relies on jQuery. Consequently, I am working to eliminate this dependency from my application entirely. One of the changes I'm making is rewriting the Ja ...

Extract information from a specific div element and save it to a text file

I'm currently working on extracting data from a div and sending it to a PHP file using the following JavaScript: $(document).ready(function(){ $('#save').on('submit',function(e) { var bufferId = document.getElementById ...

Responsive Bootstrap 4 Login Form with customized top height

This login form was created using Bootstrap 4, starting with a preset that I then customized to fit my needs. As someone new to Bootstrap and CSS, I struggled with making the form responsive. When resizing the window, the top portion gets cut off and is no ...

Ways to handle errors when using navigator.clipboard.writeText

document.queryCommandSupported('copy') may not be available on all browsers. I experimented with the code below, which successfully copies the link on Firefox but fails on Opera. It displays an alert indicating that the code has been copied, yet ...