Add design to an individual element located apart from a slider

Having a pure CSS slider, I included dot indicators to show the current slide. However, there are also numeric indicators outside of the slider that I want to change the color of.

The CSS code for the working indicators looks like this:

input#img-1:checked ~ .nav-dots label#img-dot-1,
input#img-2:checked ~ .nav-dots label#img-dot-2,
input#img-3:checked ~ .nav-dots label#img-dot-3 {
    background: rgba(0, 0, 0, 0.8);
}

Unfortunately, this code does not work for changing the color of the numeric indicators:

input#img-1:checked ~ #title label#slide-link-1,
input#img-2:checked ~ #title label#slide-link-2,
input#img-3:checked ~ #title label#slide-link-3 {
    color: red;
}

If there are more than three slides, the same issue persists. To view the code and problem, check out my codepen here: http://codepen.io/anon/pen/ZbPvde

Is there a way to achieve this using CSS alone, or could you please provide guidance on how to solve it with jQuery? Thank you for your help.

Answer №1

Instead of using classes, you are actually utilizing ids, so keep in mind that you can only use #img-dot-1, #img-dot-2, and #img-dot-3 once throughout your entire HTML page. The same rule applies for #slide-link as well. This allows you to access them directly:

#img-dot-1,
#img-dot-2,
#img-dot-3 {
    background: rgba(0, 0, 0, 0.8);
}

#slide-link-1,
#slide-link-2,
#slide-link-3 {
    color: red;
}

If setting the color: red property is still not working, try overriding it with !important like this:

#slide-link-1,
#slide-link-2,
#slide-link-3 {
    color: red !important;
}

This issue could be due to some inner elements interfering with the styling.

I have added a screenshot below to demonstrate the enhanced functionality:

https://i.sstatic.net/gigN5.png

Update: For changing the current slide number as per your requirement, I made the following modifications:

Firstly, I included the following CSS:

.red {
    color: red;
}

#img-dot-1,
#img-dot-2,
#img-dot-3 {
    background: rgba(0, 0, 0, 0.8);
}

Next, I assigned values to the checkboxes in this format:

<input type="radio" name="radio-btn" id="img-2" value="2" />

Following that, I incorporated JQuery and the subsequent script to enable the desired functionality:

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
function select(i)
{
    $("#slide-link-1").removeClass("red");
    $("#slide-link-2").removeClass("red");
    $("#slide-link-3").removeClass("red");
    $("#slide-link-"+i).addClass("red");
}
$("input[type='radio']").change(function()
{
    select($(this).val());
});
</script>

If you wish to start with the color red selected initially, add the following line to the script section:

$("#slide-link-1").addClass('red') 

That should take care of it.

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

Unable to make changes to the data

Journey Route::resource('/videofile', 'VideoController'); VideoController public function update(Request $req, $id){ $video = Video::findOrFail($id); if($req->hasFile('UserVideo')){ $vid = $req->file(& ...

Modify the text color upon clicking with a TouchableOpacity component

Would appreciate help from experienced coders. I'm just starting out with coding and React. My goal is to be able to change the text color with a click, and then change it back to the original color with another click. function handleColorChange() { ...

Having trouble viewing the CSS menu on Internet Explorer 8? Could it be a potential JavaScript issue causing the problem?

Receiving complaints about the menu bar dysfunction in Internet Explorer 8 has left me bewildered. Despite working perfectly on all other browsers and earlier versions of IE, I cannot figure out what's wrong with the code. You can view the website at ...

Gradient in Half Circle With JavaScript

How can I achieve a gradient effect within a circle using the following initial code: HTML: <div class="progresss"> <div class="barOverflow"> <div class="bar"></div> </div> <span>10</span>% </d ...

How to modify the font color of weekend dates on jquery datepicker

Can I adjust the font color of dates that land on weekends in a jQuery calendar? I attempted to utilize the class ui-datepicker-week-end but it only alters the font color for Sunday and Saturday. My aim is to also modify the color of days that fall on Su ...

Resizable item within a text box (similar to an HTML editing tool)

After extensive searching online, I have not been able to find a solution. What I need is a draggable input element within a textarea in a text-editable div. The draggable textarea should be integrated seamlessly into the text, and upon submitting, it shou ...

What is the best way to apply a border-radius to the top of bars in @nivo/bar?

Is it possible to apply a border radius to the tops of each stack in a stacked responsive bar created from the Nivo library, without affecting the bottom? Currently, the responsive bar's border radius applies to both the top and bottom. Thank you! ...

Creating duplicates of table rows featuring Glyphicon and Bootstrap for an interactive "Data Live Search" dropdown

After successfully creating rows by clicking the plus glyphicon, the Bootstrap dropdown (with live search) is not functioning in the 2nd row and subsequent rows (after cloning). Please see the provided code snippet below. Any guidance on how to resolve th ...

Painting Magic: Exploring the World of Canvas Zoom and Moves

I'm having trouble implementing zoom and pan functionality for this particular canvas drawing. While there are examples available for images, my case is different since I am not working with images. Any tips or suggestions on which libraries to use wo ...

Flipping a jQuery animation upside down

I have been exploring ways to create a reverse animation using jQuery and came across the toggle function. However, I am unsure of how to implement it in my code. Currently, my code for one-way animation is as follows: $(document).ready(function() { $(&a ...

What causes variations in layouts when using the same CSS grid code across different pages?

I've encountered an issue where the CSS on two pages, with slight color changes, is behaving differently in terms of grid layout. Despite multiple attempts to troubleshoot by adjusting items, grid-template-layout, and other parameters, the issue persi ...

The conversion of 'data' to an object in jQuery/Json is not possible

One of my simple ajax/json requests using jQuery is as follows: $.ajax({ type: "POST", url: "/some-json-url", data: "score=" + 1, dataType: 'json', success: function(data){ ...

unable to detect image input type

My dilemma lies in trying to submit a form using an image input type. The ajax request works as expected, and I receive a response from my php script. However, I encountered an issue where the image button was not changing its image upon submission. Accord ...

Fancybox may be difficult to spot when using Safari

Currently, I am utilizing fancybox with the latest versions of jquery.min.js (3.3.1), jquery.fancybox.css (3.5.7), and jquery.fancybox.pack.js (3.5.7). Everything is functioning as expected on all browsers except for Safari. On Safari, the content within ...

Verify if the username is present in the database using AJAX

I'm looking to enhance my registration form by checking if a username already exists in the database. I have some questions regarding AJAX: How can I create an AJAX request on_change function for username validation? $('#username').change(f ...

Struggling to connect the Calendar data in AngularJS

I am a beginner in angular js and facing an issue with binding the value of the calendar date from the jquery calendar picker. It seems to be accepting the date only, while all other fields are getting bound correctly. Below is my HTML code: <input id ...

Error 500 encountered during the AJAX request

Here is a snippet from my script: ......................... ......................... data = $(this).serialize() + "&" + $.param(data); $.ajax({ type: "POST", dataType: "json", url ...

Problem with the transform attribute in CSS

Having trouble rotating a div within another div. I tried using the transform property but it's not working as expected. I heard about another method which involves using :before pseudo-element, but I'm not sure what's wrong with that either ...

Tips for stopping table column width growth when an icon is inserted into a cell dynamically

In the table I have, the header is clickable and when clicked, it triggers sorting. Clicking on the header title adds an icon (ascending or descending) to the right of the title, causing the column width to increase based on the size of the icon. Refer to ...

Ensuring that two columns in Bootstrap 3 have equal heights while including padding

I would like to achieve this design without using JavaScript. Here is a screenshot for reference: This is what I have created so far using Bootstrap 3. The CSS is inline due to the use of less, which makes it easier :) HTML <section class="container ...