Is it possible to customize the appearance of HTML input fields pre-populated by the browser

My ASP.NET MVC application has a login page:

<form id="account" method="post">
        <h2>Use email account to log in.</h2>
        <hr />
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <div class="form-floating">
            <input asp-for="Input.Email" class="form-control" autocomplete="username" aria-required="true"/>
            <label asp-for="Input.Email" class="form-label"></label>
            <span asp-validation-for="Input.Email" class="text-danger"></span>
        </div>
        <div class="form-floating" >
            <input asp-for="Input.Password" class="form-control" autocomplete="current-password" aria-required="true" />
            <label asp-for="Input.Password" class="form-label"></label>
            <span asp-validation-for="Input.Password" class="text-danger"></span>
        </div>
        <div>
            <div class="checkbox form-row">
                <label asp-for="Input.RememberMe" class="form-label">
                    <input class="form-check-input" asp-for="Input.RememberMe" />
                    @Html.DisplayNameFor(m => m.Input.RememberMe)
                </label>
            </div>
        </div>
        <div class="form-row">
            <button id="login-submit" type="submit" class="w-100 btn btn-lg btn-primary">Log in</button>
        </div>
    

It utilizes bootstrap classes and looks great with a dark theme:

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

However, when the browser (tried Chrome and Edge) autofills the form, it appears unattractive, which I was informed is intentional.

Is there any way I can change the colors of the autofilled form elements?

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

EDIT: upon researching autofill, I only found these suggestions:

.form-floating > .form-control:-webkit-autofill {
       padding-top: 1.625rem;
       padding-bottom: .625rem
      }
      .form-floating > .form-select {
       padding-top: 1.625rem;
       padding-bottom: .625rem
      }
      .form-floating > .form-control: not(:-moz-placeholder-shown)~label {
       opacity: .65;
       transform: scale(.85)translateY(-.5rem)translateX(.15rem)
      }
      .form-floating > .form-control: focus~label, .form-floating > .form-control: not(:placeholder-shown)~label, .form-floating > .form-select~label {
       opacity: .65;
       transform: scale(.85)translateY(-.5rem)translateX(.15rem)
      }
      .form-floating > .form-control:-webkit-autofill~label {
       opacity: .65;
       transform: scale(.85)translateY(-.5rem)translateX(.15rem)
      }

Therefore, I added the following CSS to override it but it had no effect:

.form-floating > .form-control:-webkit-autofill {
    background-color: #dedede;
    border-color: #2a2a2a;
    color: #2a2a2a;
}

Answer №1

After much searching, I finally discovered the perfect style I was seeking:

.form-control:disabled, .form-control[readonly] {
    background-color: #dedede;
    border-color: #2a2a2a;
    color: #2a2a2a;
}

A big shoutout to @epascarello and @vee for their invaluable assistance!

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

Conceal elements that are overflowing slightly

I need help coming up with a purely CSS solution to hide div 3, which has extended beyond its container. Look at the picture linked below for reference. https://i.stack.imgur.com/isfvU.jpg ...

Submit the form using the GET method and update the URL

<form method=\"GET\" action=\"http://www.$domain/search/\"> <input type=\"search\" id=\"search\" name=\"search\" value=\"terms\"> </form> This form will be directed to the follo ...

Can a personalized user permission prompt be designed for HTML5 APIs?

Can a consistent custom user permission request dialog be designed for HTML5 APIs, such as geolocation or getUserMedia, to ensure uniform appearance on all browsers? ...

The script is malfunctioning on Google Chrome

Below is a script that I have: EXAMPLE : <script> var ul = document.getElementById("foo2"); var items = ul.getElementsByTagName("li"); for (var i = 0; i < items.length; i=i+2) { // perform an action on items[i], which repr ...

Unable to open modal in browser due to HTML, CSS, and jQuery issues

I'm having trouble creating a modal window that opens when a button is clicked for user registration. The button is being clicked, but the modal window isn't appearing. Here's my code: <script src="http://ajax.googleapis.com/ajax/libs/ ...

Which is more recommended to use in AJAX (XMLHttpRequest) - eventListener or readyStateChange method?

As I revisited a video from WWDC12 discussing advanced effects with HTML5, I couldn't help but notice that for the demo they utilized req.addEventListener("load",callback,true) instead of the usual onreadystatechange. This made me wonder: what differ ...

Adjustable width (100%) and set height for SVG

I am attempting to insert an SVG object onto my HTML page with a width of 100% and a fixed height. Upon viewing my fiddle, you will notice that the height of the dark-grey object changes based on the window proportions, which is not the desired outcome. ...

Converting Variable Values to Element IDs in JavaScript: A Helpful Guide

Is it possible to declare a value in variable A and then access that value as an id in variable B using the method getElementById()? var A = 10; var B = document.getElementById(A); console.log(B); ...

Move to Fieldset Upon Link Click

Here's an example of what I have implemented so far here It's evident that this is not fully functional due to the PHP and jQuery integration. This demo is just a showcase of my progress. I am looking to create a functionality where clicking on ...

Angular binding for selecting all data

Upon checking a checkbox for a single item, the bound data is retrieved and added to an array. However, this does not happen when using selectAll. Code snippet in Angular for obtaining the object of a checked item: $scope.selectedOrganisations = []; $sco ...

Setting the dimensions of an HTML - CSS block

I am trying to style a navigation bar using the following CSS code: #nav {} #nav a { position: relative; display: inline-block; color: #F0F0F0; width: 1em; height: 2em; line-height: 0.9em; } #nav a.ic ...

retrieving data from a node and embedding it into an HTML file

In my project, I have an index.html file and an app.js nodejs file. Within the app.js file, there is a variable named "name" that I would like to display in my index.html page. Here is the code snippet: var name = "Utsav"; var HTTP = require('HTTP&a ...

Excessive vertical space is utilized by the vertical images in the CSS grid image gallery

My responsive CSS grid gallery is experiencing issues with vertical images disrupting the layout, as they appear at full size instead of remaining square like the others. How can I fix this problem? Thank you! Below is the code snippet: <div id=" ...

Tips for establishing a fixed point at which divs cease to shrink as the browser size decreases

There are numerous dynamically designed websites where divs or images shrink as the browser size decreases. A great example of this is http://en.wikipedia.org/wiki/Main_Page The div containing the text shrinks proportionally to the browser size until it ...

How can we convert unpredictable-length JSON user input into well-structured HTML code?

Welcome to the world of web development! I am currently embarking on a project where I aim to transform JSON data into HTML structures. Specifically, I am working on creating a dynamic menu for a restaurant that can be easily updated using a JSON file. The ...

Firefoxy can't seem to get through the navigation keys within an element that has a hidden

Check out this fiddle I created: http://jsfiddle.net/c11khcak/13/. My goal is to hide the scrollbar of an element while still allowing it to be scrollable using the mouse wheel and up/down navigation keys. I've been able to achieve this using some bas ...

Looking to personalize the appearance of an iframe using CSS styling?

I am working with an iframe that generates a form, and I would like to customize the CSS of this form. How can I go about editing the CSS? <div class="quiz-container" style="text-align: center;" data-quiz="#######" data-pr ...

Can anyone recommend a high-quality jQuery lightbox replica?

Key Features Needed: Customizable with CSS Capable of handling forms, not just images Extensively documented Please provide any recommendations and suggestions for suitable options. Thank you in advance ...

How can I arrange an array of strings with dates in C# or use ordering functionality in AngularJS?

I've got an array of dates in the following format: string[] arr=["08.02.2017","09.02.2017","30.01.2017","31.01.2017"] What is the most efficient method to sort this array in C# so that the order is descending? I want the data to be displayed within ...

Use Javascript to deactivate the mouse cursor and rely solely on the keyboard cursor for navigation

I am facing an issue with a div that contains a textarea. The cursor is automatically positioned at the beginning of the text within the textarea. I would like to disable the mouse cursor when hovering over the textarea but still be able to navigate within ...