Incorporate active styling and apply CSS to the links <a> within Bootstrap buttons

Hello everyone! I am currently learning how to use bootstrap/CSS as I work on designing a website for one of my courses.

Check out the Heroku app here

At the moment, I have successfully created my header. It includes some buttons wrapped in <a> tags within divs and containers.

When using the inspector tool, it shows that the <a> tags are being targeted instead of the actual buttons. I adjusted the size of the <a> tags to match the buttons for better clickability.

I recently attempted to revamp the header by following the Bootstrap docs and implemented a jQuery script:

$(function() {
 $('button').click( function() {
$(this).addClass('active').siblings().removeClass('active');
}); 
});

This script changed the style to a white background when activated, but unfortunately, this change did not persist after redirection.

Should I consider using :visited and then removing it? I believe that :visited is a property that remains unchanged even after clicking links.

Link to the header file

Link to the CSS file

Here is the newly added CSS code that I think could be effective for targeting the path to the <a> tags.

The attributes of the header may not be relevant, but I want to ensure all information is included.

header{
 text-align: center;
 padding-bottom: 0em;

/* SHOULD THIS WORK?  */
    .navbar  .container .btn-group button.active a{
    background-color: white;
}

}

Edit to Header HTML -> The <a> Tags have width: 100%; height: 100%; so I always clicked them instead of the buttons. Didn't know a better way

<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
<div class="btn-group">

    <button type="button "class="btn btn-lg"><%= link_to current_user.name, current_user %></button>

    <button type="button" class="btn btn-lg"><%= link_to "Log Out", root_path %></button>

    <button type="button" class="btn btn-lg"><%= link_to "New Event", new_event_path %></button>

    <button type="button" class="btn btn-lg"><%= link_to "All Events", events_path %></button>

I am aiming for a design similar to the Rift website

Explore Oculus Rift here

Whether you are using Rift/Touch/Oculus Ready Pcs, their formatting differs with bold text and a line underneath. I aspire to replicate this layout for my header but with a white background instead.

Answer №1

Are you in need of

a:focus {
    background-color:white;
}

UPDATE

If you desire a persistent white background after clicking on the link, you must set up a cookie

$(function() {
    // Verify cookie existence
    if (document.cookie.indexOf("clicked") >= 0) {
        // Change header color
        $('header').css('background-color', 'white');
    } else {
        // Create button click event
        $('button').click(function(){
            $('header').css('background-color', 'white');
            // Set cookie
            document.cookie = 'clicked=1;';
        });
    }
});

Answer №2

It seems unnecessary to have a <a> nested within a <button>, but based on my understanding of your question, the following code should address your needs:

$(function() {
    $('button').click( function() {
        var nav = $('.navbar.navbar-fixed-top.navbar-inverse');
        $(this).addClass('active');
        nav.css('background-color', '#fff');
    }); 
});

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

Ways to make the Bootstrap form's fields align horizontally

I've exhausted all options, but I just can't seem to get the fields aligned horizontally. <form class="form-horizontal" role="form"> <div class="form-inline"> <div class="form-group"> <label for="acctName ...

Using special characters as parameters in Ajax requests

I need assistance with sending data via Ajax to my controller action. Here is the code snippet: $.ajax({ url: "/cotroller/action", data: { fieldsOfStudy: $('[name=fieldsOfStudy]').serialize()} }) The 'fieldsOfStudy' select bo ...

Issue with JQM popup functionality in Firefox browser

I am currently utilizing JQM 1.3.1 and have a webpage featuring various popups located at the bottom of the page: <div data-role="page" data-title="Strategic Plans"> <div data-role="content" id="capbPlans" data-bind="cafeLiveScroll: { callbac ...

A vibrant loading animation within a pop-up window

I have implemented an ajax spinner on my page using the following code: $(document) .ajaxStart(function () { $loading.show(); }) .ajaxStop(function () { $loading.hide(); }); Now, I want to display the spinner ...

Save the status of checkboxes in a JSON file using boolean values of true or false

When a user submits a form, I am retrieving the values of checkboxes and storing them as an array. The simplified form structure is as follows: <!-- gym_create.html - other input fields are omitted for brevity --> <form class="create-gym" role=" ...

What could be causing my JavaScript code to fail in passing the value from one div to another?

In an effort to transfer the content of one div into another, I am facing a challenge. Let's take a look at the pertinent HTML snippet: <div id="main"> hello </div> The goal is to create a function that retrieves the text from the c ...

The Bootstrap 4 dropdown menu is extending beyond the page boundary to the right

I'm having an issue with the dropdown menu in my Bootstrap4 navbar. It's extending past the page on the right side and I've tried a few solutions I found online, like adding dropdown-menu-left or drop-left, but they didn't work for me. ...

Clustering in an environment requires merging and minifying granules

While Granule is effective for minifying and merging CSS/JS files on a local environment, it presents challenges in clustered environments. The issue arises when each node of the cluster computes its own file during runtime, causing discrepancies when a us ...

Renew the Look of Dynamic HTML with Updated Styles

In the middle of my website, there is a console that contains links to dynamically update its content using javascript. Everything works smoothly, but the new HTML added dynamically does not have any styling applied to it. Is there a way to refresh the CS ...

Unusual actions observed in ajax rails form calculator with pre-filled values

I have a form calculator in Rails that utilizes AJAX without a database. While it functions properly, I have noticed some peculiar behavior which I would like to address. Firstly, I navigate to the /interest_calculator page Then, I input 10 into @first_0 ...

When fetching data from a parse object, JavaScript displayed [object, Object] as the result

When trying to access information from my parse data, I am able to display user table data on my document without any issues. However, when I attempt to query another object and insert it into an id element using jQuery with functions like text();, html(); ...

Why is there a mysterious white bar appearing on the right side of my Bootstrap page?

I am currently working on optimizing my bootstrap landing page to be responsive across all screen sizes. I have begun implementing media queries to ensure that the page layout adjusts appropriately for iPhones, iPads, and other devices. However, when tes ...

What ways can we implement identification features in Flutter Web applications, such as adding an ID or name property?

While developing a Flutter Web application, I am exploring a Web-UI-Testing framework that is Selenium-based. Unfortunately, I am struggling to locate an HTML element that represents a specific flutter widget by its id or name attribute. The widget key doe ...

What is the method to access an HTML page div using JavaScript?

I'm currently developing a login page using phonegap with android. Upon successful login validation, I need the user to be directed to the welcome section if they are authorized. Here is my javascript code from the file called myjavascrpt.js: var ...

Searching and retrieving database results from inside a Bootstrap modal

Can I execute a MySQL database query from within a Bootstrap modal, based on user selection, and display the results in the same modal without it closing? Below is an example of the two drop-down menus in my modal. <div class="tab-pane" id="relevance"& ...

Issues with JavaScript causing slideshow to malfunction

I'm experiencing some issues with my image slider. It seems that during the initial loop, the slideshow keeps reverting back to 'image3'. However, after the first loop, everything appears to work correctly. I am looking for a solution to ens ...

CSS background-image property should not alter the size of the first image

I am attempting to ensure that two images have the same dimensions without altering the size of the first image. My current code looks like this: background-image: url("1.png"), url("2.jpg"); background-position: 3% 10%, 83% 27%; background-size: auto, ...

Steps to update XmlHttpRequest URL during image upload

I am currently facing an issue with updating images on my website. When I try to update an image, it redirects to the wrong URL instead of the intended one. The form is set to post data to this URL: POST http://127.0.0.1/mgt/upload/processImage/foodImage ...

Python's dcc.Location is creating a fresh page nested within an existing page

I have created multiple dash apps in different HTML files, here is an example of an HTML file with the 'viewer' app: {% extends 'base.html' %} {% load static %} {% block content %} {% load plotly_dash %} <h1>Viewer</h1& ...

JavaScript Fullcalendar script - converting the names of months and days

I recently integrated the Fullcalendar script into my website (https://fullcalendar.io/). Most of the features are functioning correctly, however, I am seeking to translate the English names of months and days of the week. Within the downloaded package, ...