The text color of the tabs turns black when a tab is selected - I receive my results after clicking anywhere on the screen

I am currently using HTML, CSS, and Bootstrap to design some tabs. Here is the current result I am achieving:

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

When clicking anywhere on the screen, I see the original results based on my code.

The outcome after clicking anywhere on the screen

How can I address these two issues:

  1. Upon selecting/clicking any tab, I want the text color of the tab to change to red. I have already attempted using the "active" keyword as evident in my code.

  2. The actual result should be displayed immediately, without requiring a click anywhere on the screen.

Here's my code:

<div class="container">
<div class="row">
    <div class="col-md-12">
        <div class="tab" role="tabpanel">
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active"><a href="#medicalNotes" aria-controls="home" role="tab" data-toggle="tab">Medical Notes</a></li>
                <li role="presentation" ><a href="#medication" aria-controls="profile" role="tab" data-toggle="tab">Medications</a></li>
                <li role="presentation"><a href="#allergies" aria-controls="messages" role="tab" data-toggle="tab">Allergies</a></li>
                <li role="presentation"><a href="#vitalsh" aria-controls="messages" role="tab" data-toggle="tab">Vital Social History</a></li>
                <li role="presentation"><a href="#familyhh" aria-controls="messages" role="tab" data-toggle="tab">Family Health History</a></li>
            </ul>
            <div class="tab-content tabs">
                <div role="tabpanel" class="tab-pane fade in active" id="medicalNotes">
                    <h3>Section 1</h3>
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce semper, magna a ultricies volutpat, mi eros viverra massa, vitae consequat nisi justo in tortor. Proin accumsan felis ac felis dapibus, non iaculis mi varius.</p>
                </div>
                <div role="tabpanel" class="tab-pane fade" id="medication">
                    <h3>Section 2</h3>
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce semper, magna a ultricies volutpat, mi eros viverra massa, vitae consequat nisi justo in tortor. Proin accumsan felis ac felis dapibus, non iaculis mi varius.</p>
                </div>
                <div role="tabpanel" class="tab-pane fade" id="allergies">
                    <h3>Section 3</h3>
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce semper, magna a ultricies volutpat, mi eros viverra massa, vitae consequat nisi justo in tortor. Proin accumsan felis ac felis dapibus, non iaculis mi varius.</p>
                </div>
                <div role="tabpanel" class="tab-pane fade" id="vitalsh">
                    <h3>Section 4</h3>
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce semper, magna a ultricies volutpat, mi eros viverra massa, vitae consequat nisi justo in tortor. Proin accumsan felis ac felis dapibus, non iaculis mi varius.</p>
                </div>
                <div role="tabpanel" class="tab-pane fade" id="familyhh">
                    <h3>Section 5</h3>
                    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce semper, magna a ultricies volutpat, mi eros viverra massa, vitae consequat nisi justo in tortor. Proin accumsan felis ac felis dapibus, non iaculis mi varius.</p>
                </div>
            </div>
        </div>
    </div>
</div>

CSS

a:hover,a:focus{
    text-decoration: none;
    outline: none;
}
.tab .nav-tabs{
    border: none;
    border-bottom: 2px solid #dc697f;
    margin: 0;}
.tab .nav-tabs li a{
    padding: 10px 20px;
    margin: 0 10px -1px 0;
    font-size: 13px;
    font-weight: 800;
    color: #6da1b7;
    text-transform: uppercase;
    border: 2px solid #e6e5e1;
    border-bottom: none;
    border-radius: 5px 5px 0 0;
    z-index: 1;
    position: relative;
    transition: all 0.3s ease 0s;
}
.tab .nav-tabs li.active a{
    background: #fff;
    color: #6da1b7;
    border: 2px solid #dc697f;
    border-bottom-color: transparent;
    border-top-width: 3px;
    border-right-width: 1px;
    border-left-width: 1px;
    border-radius: 7px;
}
.tab .nav-tabs li a:before{
    content: "";
    display: block;
    height: 3px;
    background: #fff;
    position: absolute;
    bottom: -2px;
    left: 0;
    right: 0;
    transform: scaleX(0);
    transition: all 0.3s ease-in-out 0s;
}
.nav-tabs > li > a{
    color: #D33E1E;
}
.tab .nav-tabs li.active a:before,
.tab .nav-tabs li a:hover:before{ transform: scaleX(1); }
.tab .tab-content{
    padding: 10px;
    font-size: 19px;
    color: #6f6f6f;
    line-height: 30px;
    letter-spacing: 1px;
    position: relative;
}
@media only screen and (max-width: 479px){
    .tab .nav-tabs{ border: none; }
    .tab .nav-tabs li{
        width: 100%;
        text-align: center;
        margin-bottom: 15px;

    }
    .tab .nav-tabs li a{
        margin: 0;
        border-bottom: 2px solid transparent;
    }
    .tab .nav-tabs li a:before{
        content: "";
        width: 100%;
        height: 2px;
        background: #dc697f;
        position: absolute;
        bottom: -2px;
        left: 0;
        }
}

Answer №1

The color in this scenario is being overridden by the `nav.less` css file. It's worth noting that using `!important` is not ideal practice. Instead, consider increasing the specificity by utilizing a different selector that is not the same as `nav.less`, such as targeting `a` elements that have an `href` attribute beginning with `#`. For example - `.tab .nav-tabs li.active a[href^="#"]`.

a:hover,
a:focus {
  text-decoration: none;
  outline: none;
}

.tab .nav-tabs {
  border: none;
  border-bottom: 2px solid #dc697f;
  margin: 0;
}

.tab .nav-tabs li a {
  padding: 10px 20px;
  margin: 0 10px -1px 0;
  font-size: 13px;
  font-weight: 800;
  color: #6da1b7;
  text-transform: uppercase;
  border: 2px solid #e6e5e1;
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  z-index: 1;
  position: relative;
  transition: all 0.3s ease 0s;
}

.tab .nav-tabs li.active a[href^="#"] {
  background: #fff;
  color: red;
  border: 2px solid #dc697f;
  border-bottom-color: transparent;
  border-top-width: 3px;
  border-right-width: 1px;
  border-left-width: 1px;
  border-radius: 7px;
}

.tab .nav-tabs li a:before {
  content: "";
  display: block;
  height: 3px;
  background: #fff;
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  transform: scaleX(0);
  transition: all 0.3s ease-in-out 0s;
}

.nav-tabs>li>a {
  color: #D33E1E;
}

.tab .nav-tabs li.active a:before,
.tab .nav-tabs li a:hover:before {
  transform: scaleX(1);
}

.tab .tab-content {
  padding: 10px;
  font-size: 19px;
  color: #6f6f6f;
  line-height: 30px;
  letter-spacing: 1px;
  position: relative;
}

@media only screen and (max-width: 479px) {
  .tab .nav-tabs {
    border: none;
  }
  .tab .nav-tabs li {
    width: 100%;
    text-align: center;
    margin-bottom: 15px;
  }
  .tab .nav-tabs li a {
    margin: 0;
    border-bottom: 2px solid transparent;
  }
  .tab .nav-tabs li a:before {
    content: "";
    width: 100%;
    height: 2px;
    background: #dc697f;
    position: absolute;
    bottom: -2px;
    left: 0;
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="container">
  <div class="row">
    <div class="col-md-12">
      <div class="tab" role="tabpanel">
        <ul class="nav nav-tabs" role="tablist">
          <li role="presentation" class="active"><a href="#medicalNotes" aria-controls="home" role="tab" data-toggle="tab">Medical Notes</a></li>
          <li role="presentation"><a href="#medication" aria-controls="profile" role="tab" data-toggle="tab">Medications</a></li>
          <li role="presentation"><a href="#allergies" aria-controls="messages" role="tab" data-toggle="tab">Allergies</a></li>
          <li role="presentation"><a href="#vitalsh" aria-controls="messages" role="tab" data-toggle="tab">Vital Social history</a></li>
          <li role="presentation"><a href="#familyhh" aria-controls="messages" role="tab" data-toggle="tab">Family Health history</a></li>
        </ul>
        <div class="tab-content tabs">
          <div role="tabpanel" class="tab-pane fade in active" id="medicalNotes">
            <h3>Section 1</h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce semper, magna a ultricies volutpat, mi eros viverra massa, vitae consequat nisi justo in tortor. Proin accumsan felis ac felis dapibus, non iaculis mi varius.</p>
          </div>
          <div role="tabpanel" class="tab-pane fade" id="medication">
            <h3>Section 2</h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce semper, magna a ultricies volutpat, mi eros viverra massa, vitae consequat nisi justo in tortor. Proin accumsan felis ac felis dapibus, non iaculis mi varius.</p>
          </div>
          <div role="tabpanel" class="tab-pane fade" id="allergies">
            <h3>Section 3</h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce semper, magna a ultricies volutpat, mi eros viverra massa, vitae consequat nisi justo in tortor. Proin accumsan felis ac felis dapibus, non iaculis mi varius.</p>
          </div>
          <div role="tabpanel" class="tab-pane fade" id="vitalsh">
            <h3>Section 4</h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce semper, magna a ultricies volutpat, mi eros viverra massa, vitae consequat nisi justo in tortor. Proin accumsan felis ac felis dapibus, non iaculis mi varius.</p>
          </div>
          <div role="tabpanel" class="tab-pane fade" id="familyhh">
            <h3>Section 5</h3>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce semper, magna a ultricies volutpat, mi eros viverra massa, vitae consequat nisi justo in tortor. Proin accumsan felis ac felis dapibus, non iaculis mi varius.</p>
          </div>
        </div>
      </div>
    </div>
  </div>

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

Animating ng-switch transitions within a div element

Utilizing bootstrap 3 panel along with ng-switch for a sliding animation: Check out the Plunker here I am facing an issue where the animation extends past the borders of the panel instead of staying within it. How can I fix this in my Plunker? The desire ...

What can I do to ensure that the values of a vector in an array remain constant?

Is there a way to store vector data in an array without it being affected when the original vector values are changed? I inserted a vector into an array and when I modified its values, the corresponding values in the array also changed. const array10 = []; ...

"Make your slides smooth and responsive with the unslick option in slick

Currently implementing the Slick Slider on a WordPress website. The slider is designed to display 3 columns at a screen size of 1024px and above. When the screen size drops below 1024px, the slider adjusts to show 2 columns, and on mobile devices, it swit ...

Inquiries regarding the formatting of HTML tables

image description hereI'm facing an issue with displaying a table in HTML. I've been struggling for three days to find a solution, asked multiple questions without success. Any help would be greatly appreciated. I am trying to use the table tag a ...

Using ReactJS and Ruby on Rails to implement an AJAX delete request

There is a component named Items residing inside a parent component called ItemsContainer. A click on a button within the Items component triggers an Ajax function to delete that specific Item. However, I am encountering a 500 error message at the moment ...

obtaining data from an HTML input field

I'm struggling to retrieve the value from an HTML input element, and despite my own research, it seems like I have the correct syntax. However, I'm still unable to get it to work, leaving me confused. When I log the value to the console, it appe ...

PhantomJS 2.0.0 not delaying page loading

In the script provided, there is an array of URLs called links. The function gatherLinks() is designed to collect additional URLs from the sitemap.xml file related to the ones in the links array. Once the number of URLs in the links array reaches a certain ...

What could be causing the state to not update as anticipated?

I am currently in the process of developing a TicTacToe game and have a requirement to maintain the current player in state under the name currentPlayer. The idea is that after one player makes a move, I need to update currentPlayer to represent the opposi ...

Transmit the Selected Options from the Checkbox Categories

Here's an intriguing situation for you. I've got a webpage that dynamically generates groups of checkboxes, and their names are unknown until they're created. These groups could be named anything from "type" to "profile", and there's a ...

Aligning text inputs inline within a Bootstrap form for a cleaner and organized

I am currently working on designing a form using Bootstrap, and I have a specific requirement where the first name and last name fields need to be displayed inline while the rest of the form remains unchanged. Although I have managed to make the inline fu ...

Express.js experiencing difficulty integrating with Share.js

When it comes to Server-Side code, var express = require('express'); //Web Framework var app = express(); var http = require('http').Server(app); //HTTP server module var connect = require('connect'), sharejs = require(&a ...

When choosing an input field, it consistently yields an undefined value

Whenever I attempt to select an option in the input field, it should set the state value to the selected option. However, it keeps returning undefined. I am utilizing Semantic UI React Forms for input, but every time I select an option and submit, it retu ...

What is the best way to utilize JSON data stored in a Jekyll _data folder?

As per the documentation on Jekyll, it is mentioned that you can access YAML, JSON, and CSV files located in the `_data` directory using `{{ site.data.filename }}`. I have a geoJson file named `chapters.json` which consists of point features. While I am a ...

Try utilizing a dynamically created JSON object in place of using d3.json

I spent a considerable amount of time trying to solve this issue, but unfortunately I was unsuccessful. I know how to render a d3 tree with an external file, but I'm struggling with how to do it with a generated object. I am retrieving a JSON object t ...

The Keydown Event in Asp.net GridView may sometimes fail to be triggered

While working within a gridview on Internet Explorer, users can click on cells in one column to reveal a hidden textbox. After entering text into the textbox, users are instructed to press the Tab key to save changes. To accomplish this, a Javascript funct ...

Code for Custom Controllers in Strapi Beta version 3.0

I have encountered some discrepancies in the beta version of Strapi's controllers compared to the previous version. The new version includes multipart/sanitization boilerplate, and I am having trouble integrating my order object and Stripe charge. Be ...

Is there a way to use JavaScript to import several custom fonts at once?

Is there a way to import a long list of custom fonts as icons using Javascript? I have been obtaining the font list from an API, but importing them one by one with pure CSS using @font-face is time-consuming and difficult to maintain. @font-face { fon ...

"By clicking on the image, you can trigger the transfer of data to the view.py file

Check out my image in two.html: https://i.sstatic.net/FhKlz.png <td> <img src="http://127.0.0.1:8000/imageAll/101.png" width="100"; height="300"> </td> I need to pass the data value of 101 to my view.py wh ...

Custom field data in WordPress

I'm having difficulty formatting the prices of certain products using a custom field (unit_price). The value is 3.2, but the code only displays 3 because it doesn't recognize commas or dots. Is there a way to display the full value? any assistanc ...

The error message "Uncaught TypeError: Unable to retrieve the 'lat' property of an undefined object when serializing leaflet data using $.param()" is displayed

Being a complete novice in JavaScript, I am experimenting with posting user location and map bounds using Leaflet and an AJAX call. While my event handler stateUpdater.onLocationFound successfully logs the user coordinates and map bounds, I encounter an is ...