CSS/HTML code for creating a dynamic border on specific pages

Currently, I am working on creating a border button that becomes active when you are on the corresponding page. The challenge is that when you click on a different border button, the first one's border disappears and the second one becomes visible instead. This functionality is similar to what you see on websites like this one, where buttons such as "Questions, Jobs, Documentation Beta, Tags" light up when selected while others turn off. I attempted to search for a solution on Google without success and also inspected the elements using Google Chrome's developer tools.

Answer №1

Ensure consistency in your HTML across all pages, and then customize the appearance of each button by adding an 'active' class to the respective button on each page. Here's an example:

For the Home page

<a class="button active" href="index.html">Home</a>
<a class="button" href="about.html">About</a>

For the About page

<a class="button" href="index.html">Home</a>
<a class="button active" href="about.html">About</a>

CSS

.button {
background-color: grey;
}

.active {
background-color: orange;
}

Answer №2

To easily highlight a button on a webpage, consider adding an "active" class to that specific button.

Answer №3

To achieve the desired styling and functionality for an activatable element, a combination of CSS and HTML is necessary. However, if you also want this element to be activated without refreshing the page, some JavaScript will be needed as well.

$('button').on('click', function() {
  $('button').removeClass('active');
  $(this).addClass('active');
});
button.active {
  background: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button class="active">Active Tab</button>
<button>Inactive Tab</button>

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

Is there a way to include an instance variable as a CSS rule in Rails?

Assume I have the following ActiveRecord class: ......... store :skin_properties, accessors: [ :background_color, :font_size, :font_family, :color ] ......... This class saves values in the format shown below: {"background_color"=> ...

Using jQuery to define and apply style attributes

I'm currently working on a script that will add a left and right border to a button in a row of 3 buttons when that specific button is clicked. The goal is for the borders to remain while the button is active, and disappear once another button is clic ...

Executing cssnano Using the Command Prompt

Although I'm not an expert in node JS, I have come across cssnano as a JavaScript tool for minifying CSS, which apparently does a more sophisticated job compared to the outdated YUI compressor. My only issue is that I am struggling to understand how t ...

Trouble Aligning Bootstrap Dropdown Menu Link with Other Navbar Links

Issue with dropdown links not aligning properly in the Bootstrap navbar. The positioning seems off and can be seen in the screenshot provided where the blue outline represents the ".dropdown" https://i.stack.imgur.com/QmG7v.png Facing a similar problem a ...

The issue with jqTransform not displaying the select box value on a hidden contact form

Could really use some assistance here and apologize if it's a hassle: Link to contact form To view the contact form, simply click the "Contact" button in the top left corner. The jqTransform jQuery plugin is being used to style it. Initially, it&apo ...

Maintaining the order of elements in Angular's insertion process

I am currently facing an issue with my HTML fragment that iterates over a key and value collection. Everything works perfectly when I insert values into an object and iterate through it using the HTML fragment. However, in order to maintain a specific key ...

validating forms with an abundance of checkboxes

Currently, I am in the process of creating a checkbox form that consists of more than 200 questions (yes, I know, quite ambitious!). My main requirement is to prevent the user from advancing to the results page unless they have checked at least one checkbo ...

<dt> and <dd> have not been added after the previous element

I can't seem to figure out why the dt and dd elements are not being added to the dl I created. Here's my initial attempt: // Dictionary list var words = [ { term: "Procrastination", definition: "Pathological tendency to s ...

Achieving full screen height at 100% with the CSS property of display: table along with table-cell tag

I'm facing an issue with the layout of my page. In this example (http://jsfiddle.net/RR2Xc/2/), the footer is not positioned at the bottom as desired. If I force the footer to be at the bottom, it creates a gap between the sidebar and footer where the ...

Attempting to modify the background hue of a grid component when a click event is triggered

I am struggling with the syntax to change the color of an element in my grid when clicked. I have attempted different variations without success. Being new to JavaScript, I would appreciate some gentle guidance if the solution is obvious. JS const gri ...

The inclusion of HTTP header information within a jQuery file led to the unsuccessful loading of the jquery.js file

There's a strange issue occurring in my project. To give some context, the project is built using HTML, Extjs, and JSON. When the page loads in the browser, I noticed that header information is being dynamically added to the jQuery file. This unexpect ...

Use ngFor to align items to the left in your design

I am working on a div element where I need to dynamically add inputs that should form a number with a specific format. To ensure the inputs start from the left, I have applied the justify-content-end class. HTML: <div class='row justify-content-end ...

Transmit data from Raspberry Pi to Apache Server with strong security measures

Utilizing a Raspberry Pi to collect temperature data and store it in a file Running on a virtual machine, the server uses Apache to host a website (comprised of HTML, PHP, and JavaScript) displaying a graph based on this data I am seeking a secure method ...

A technique for adding a border to a Mat Card that mimics the outline of a Mat Form Field within a custom

I am faced with a unique design challenge where I am utilizing the MatCardComponent and each card contains a table. I would like to incorporate a floating label within the border gap similar to what is seen in MatFormField. https://i.stack.imgur.com/51LBj ...

AmCharts Axis renderer mistakenly renders an additional grid line

I have successfully created a basic XYChart using amcharts4. To get rid of the grid lines on the x-axis, I changed the stroke opacity for the x-axis grid to 0 using the following code: xAxis.renderer.grid.template.strokeOpacity = 0; Everything was workin ...

Centered Menu with Left Alignment

I am trying to figure out how to align a sublist directly under a main list point that is centered. I have attached some images to show what I am aiming for: Currently, when I center the main list point (LEISTUNGEN), I am facing issues placing the sublist ...

`.svg file appearing slightly fuzzy when magnified in Chrome``

After careful consideration, I've chosen to use an SVG for my website logo. However, I am facing an issue with it rendering properly in Google Chrome. When the zoom level is set at 100%, the image appears blurry, but if I zoom out a couple of times, i ...

Issue with displaying multiple checkboxes using Materialize CSS in combination with Leaflet for web-mapping overlays

I'm currently using Materialize 0.97.7 along with Leaflet 1.0.1 (the latest version). <script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.1/leaflet-src.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com ...

Footer not positioned at the bottom of the page

I have been experimenting with different ways to keep my footer at the bottom of the page. Initially, I tried using position: static, but the footer ended up above the bottom of the page and the background was visible (similar to the image below). Then, I ...

Is it possible to adjust the width of the comment box on the Facebook "Like" button?

Is there a way to set the width of the comment box that appears after clicking the Facebook "Like" button? I know how to adjust the width of the button itself and related content, but can't find any options for the comment box: I've tried overri ...