How can I fix the issue of CSS styles not being applied to a button and remove the blue highlight when clicked

Recently, I encountered a problem while developing a web application using HTML, CSS, and JS in PyCharm. The issue is with the upload button that should trigger the uploading of source code. Despite being new to this, I have been unable to find a solution.

When you click or hold down the "Upload" button, it displays an unexpected visual glitch where it turns blue. Although holding it down is not necessary, even a brief click results in this blue color appearing.

View the upload button gif here

Below is the CSS code I am currently using:

.btn-primary {
    background-color: #fc3e00;                       
    border: none;                                    
    border-radius: 5px;                              
    transition: background-color 0.3s ease, transform 0.2s ease; 
    color: white;                                    
    appearance: none;                                
}

.btn-primary:hover {
    background-color: #b80c09;                       
}

.btn-primary:focus {
    outline: none !important;                        
    box-shadow: none !important;                     
    background-color: #b80c09;                       
}

.btn-primary:active {
    background-color: #b80c09;                       
    transform: scale(0.95);                           
    box-shadow: none !important;                      
}

And here is the HTML code snippet:

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap Link -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

    <!-- CSS Link -->
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

    <!-- Font Link -->
    <link href="https://fonts.googleapis.com/css?family=Roboto+Mono:100,100i,300,300i,400,400i,500,500i,700,700i"
          rel="stylesheet"/>
    <!-- Project Name -->
    <title>Viewie - Source Code Visualizer</title>
</head>
<body>
    <div class="container">
        <h1 class="text-center mt-4">Welcome to Viewie: A Code Source Visualizer!</h1>
        <h2 class="text-center mt-4">Input your Python, Javascript, or Java Code :D</h2>
        <form id="codeForm" class="mt-4">
            <div class="form-group">
                <textarea class="form-control" id="code" rows="10" placeholder="Please upload your source code :)"></textarea>
            </div>
            <button type="submit" class="btn btn-primary">Upload</button>
        </form>
        <div id="output" class="mt-4"></div>
        <div id="umlDisplay" class="mt-4"></div>
    </div>

    <script src="{{ url_for('static', filename='script.js') }}"></script>
</body>
</html>

I attempted setting the outline to none and adjusting the box-shadow as a fix, but so far, it has not resolved the issue. While searching for solutions, I found similar suggestions for mobile devices, but nothing specific for non-mobile platforms, unless I have overlooked something. Additionally, I have refreshed the page and tried accessing the application on a different browser like Firefox without any change in behavior.

Answer №1

Adding !important to the colors in the CSS file is necessary for ensuring the correct appearance of the button.

.btn-primary {
    background-color: #fc3e00 !important;                       
    border: none !important;                                    
    border-radius: 5px;                              
    transition: background-color 0.3s ease, transform 0.2s ease; 
    color: white;                                    
    appearance: none;                                
}

.btn-primary:hover {
    background-color: #b80c09 !important;                       
}

.btn-primary:focus {
    outline: none !important;                        
    box-shadow: none !important;                     
    background-color: #b80c09 !important;                       
}

.btn-primary:active {
    background-color: #b80c09 !important;                       
    transform: scale(0.95);                           
    box-shadow: none !important;                      
}
  <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- Bootstrap Link -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">

    <!-- CSS Link -->
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">

    <!-- Font Link -->
    < link href = "https://fonts.googleapis.com/css?family=Roboto+Mono:100,100i,300,300i,400,400i,500,500i,700,700i"
          rel = "stylesheet"/>
    <!-- Project Name -->
    <title> Viewie - Source Code Visualizer </ title>
< / head>
< body >
    < div class = "container" & gt ;
        < h1 class = "text-center mt-4" & gt ; Welcome to Viewie: A Code Source Visualizer!& lt; / h1 & gt;
        < h2 class="text-center mt-4">Input your Python, Javascript, or Java Code :D</h2>
        < form id = "codeForm"class="mt-4">
            < div class = "form-group" & gt ;
                < textarea class = "form-control"id="code"rows="10"placeholder="Please upload your source code :)"> & lt; / textarea>
            < / div>
            < button type = "submit"class="btn btn-primary">Upload</button>
        </ form>
        < div id = "output"class="mt-4"></div>
                                & lt; div id = "umlDisplay"class="mt-4"> & lt; / div & gt;
                                & lt; / div & gt ;

                                & lt; script src = "{{ url_for('static', filename='script.js') }} "></script>
                            & lt; / body & gt ;
                        & lt; / html & gt;

Answer №2

Tip: Utilizing the :focus pseudo-class

If your CSS already has styles set for the .btn-primary:focus state, you can include the outline: none; property to eliminate the default browser outline:

.btn-primary:focus {
  outline: none !important;
  box-shadow: none !important;
  background-color: #b80c09;
}

Make sure to also check the browser cache for any conflicting Bootstrap styles, which is why !important is added to override them if necessary.

The :focus pseudo-class applies styles to an element when it is focused, with the outline property controlling the outline around the focused element.

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

Web links do not adjust properly on mobile pages

Weblinks are causing issues with responsiveness on my website, as they are increasing the mobile page width and resulting in a poor user experience. I am currently using the Asona theme. Please help me resolve this issue - the weblinks are not wrapping t ...

Highlighting of tab CSS is not persistent when switching tabs or clicking elsewhere on the page

Using Bootstrap 4, a navigation tab is created. However, upon loading the page, the home tab is automatically loaded but not highlighted. Clicking on any tab will highlight it correctly, but once clicked anywhere else on the page, the highlight disappears. ...

"Exploring databases with MySQL and displaying dynamic outcomes with PHP

I am a beginner in PHP and I am attempting to create a basic search engine. My goal is to display a summary of the search results on an HTML page after each search, showing all the items that match the query. Each item summary should include a link to a sp ...

Decrease the height of h1 by using the display property set to table-cell

I managed to center text inside a table cell using display: table-cell, vertical-align: middle, and text-align: center. However, I'm experiencing unwanted spacing above and below the text. How can I completely eliminate it? I want zero margin/padding ...

What could possibly be causing the 500 server error in PHP?

It's frustrating - every time a user tries to enter their email and password, an error 500 message pops up on the server! But strangely enough, upon refreshing the page, everything seems to work just fine... So why does the server throw an error on th ...

The user_login view in the account views did not provide an HttpResponse object, but instead returned None

Error: Unable to register or log in - account.views not returning HTTP response # accounts/views.py from django.shortcuts import render, redirect from django.contrib.auth import login, authenticate, logout from account.forms import RegistrationForm, Use ...

Incorporate a JavaScript solution for generating a dropdown menu, rather than relying on

I have been exploring a code snippet that dynamically creates and deletes text boxes using JavaScript. Here is the link to the code in action: http://jsfiddle.net/JpYGg/8/ My goal now is to modify this functionality to generate a set of three drop-down li ...

Currently studying PHP. The classic "Hello world" message is not appearing when using EasyPHP and coding in Notepad++

<html> <!--HTML--> <head><title>a simple test</title></head> <body>a basic test</body> <p>javascript</p> <!--javascript--> <p><script> document.write("hello universe") </sc ...

Generate a new div element by simply tapping on a button

I want to create a new div by clicking on a button that contains a form. Each div (form) should include information about a specific plane. Once I click on the save button, each plane should be saved in the database. I have started creating the form but I ...

What is the most effective method for implementing grid-based scrolling in a top-down RPG game?

In my browser-based application, which is currently built using PHP, JavaScript, HTML5, and jQuery as the only framework, I have a question regarding image scrolling. If I have enough 64x64 images to fill up my screen about 100 times, what technique would ...

Sorting depth based on z-index in a three.js render depth algorithm

My current project involves rendering planes with textures and sprites, all of which have transparent PNG textures. However, I've noticed a problem with transparency when objects overlap. I attempted to capture a screenshot of the issue for reference ...

Align the inner container in the outer container-fluid

I'm struggling to center a container inside a container-fluid. Any suggestions on how to make it work? /* Setup Buttons Specific Styling */ .setup-bg { background: url("https://image.ibb.co/geAGqy/setupbtns_bg.png"); background-repeat: no-repea ...

Determine the location of a character based on its index position

Is it feasible to identify the precise x and y coordinates of the character at position 24 (e.g., '-') in this overflowing multi-line text? ...

Ways to ensure the background color stretches the entire length of the page

I've been attempting to create a background image or color that extends across the entire main content area, but haven't had any success so far. For reference, please visit My attempts have involved adding a class called fill to the container-f ...

Angular select element is not functioning properly with the `addEventListener` method

My current project involves creating a table using the primeng library. The table consists of three rows and three columns, and all the data is static. Even though I am utilizing an external library, I find myself traversing the DOM directly. <p-table ...

Using Razor view form with various submit buttons

In my razor view, I have a BeginForm command surrounded by a loop that generates an HTML table with a submit button in each row. My concern is how do I identify which specific row the submitted form corresponds to when sending it back to the controller? T ...

Adjust the width of a textarea dynamically as you type by detecting keyup events

Two text areas have the same text formatting. Their IDs are textareaA and textareaB. I've successfully added functionality to resize textareaA on keyup. How can I make textareaB resize its WIDTH while the user is typing in textareaA? Here's wha ...

Creating a sidebar that overlaps the footer with CSS

Is there a way to make my sidebar overlap the footer? I attempted using position:absolute without success. .sidebar-menu { list-style: none; margin: 0; padding: 0; } element.style { padding-bottom: 25px; } .main-footer { background: #fff; padding: 15p ...

React createElement function does not include string children when there are multiple children present within the inner HTML

Currently, I am utilizing React.createElement(...) to dynamically produce a basic react website using data from a JSON file. The JSON file consists of an array of JSON objects that represent elements and their respective children. An individual element&ap ...

jQuery sliding toggle effect combining multiple div sets

I have two columns, A & B. Some items in A open multiple items in B. A will toggle its corresponding B Items - BUT clicking on an A that includes an already opened B starts to mess up the toggle. I want each item in A to open its respective items in ...