Border disappears with autocomplete feature

Despite setting autocomplete to off in my form, modern browsers tend to override this. An issue arises where the border of a user's input field remains intact when they manually type their name, but is removed when the browser autofills it.

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

.half {
  width: 50%;
  margin-left: auto;
  margin-right: auto;
}

input[type=name] {
  width: 100%;
  padding: 15px;
  display: inline-block;
  margin-bottom: 10px;
  outline: none;
  border-radius: 30px;
  box-sizing: border-box;
  border: solid 5px transparent;
  background-image: linear-gradient(white, white), radial-gradient(circle at top right, #006699, #9900CC);
  background-origin: border-box;
  background-clip: padding-box, border-box;
  font-family: 'Roboto', sans-serif;
  font-size: 15px;
  box-sizing: border-box;
}

.contain {
  width: 100%;
  min-width: 100%;
  max-width: 100%;
  min-height: 200px;
  max-height: 200px;
  margin-bottom: 10px;
  background-image: linear-gradient(white, white), radial-gradient(circle at top right, #006699, #9900CC);
  background-origin: border-box;
  background-clip: padding-box, border-box;
  border: solid 5px transparent;
  border-radius: 30px;
  padding: 0;
  overflow: hidden;
  box-sizing: border-box;
}

textarea {
  width: 100%;
  min-width: 100%;
  max-width: 100%;
  min-height: 200px;
  max-height: 200px;
  padding: 15px;
  resize: none;
  display: inline-block;
  outline: none;
  border: none;
  box-sizing: border-box;
  font-family: 'Roboto', sans-serif;
  font-size: 15px;
  border-radius: 30px;
  box-sizing: border-box;
}
<div class="half">
  <form method="post" name="submitted" action="submitted" autocomplete="off">
    <input type="name" id="forename" name="forename" placeholder="Forename"><br>
    <div class="contain">
      <textarea></textarea>
    </div>
    <br>
    <input type="submit" name="submit" id="submit" value="Contact Me" required="">
  </form>
</div>

Is there a way to keep the border even when the field is autocompleted, considering that complete disabling of autocomplete is not feasible?

Answer №1

Primarily, it is impossible to alter the background styles of Chrome's :-webkit-autofill using CSS. While we can manipulate other properties, changing the background is not an option. One workaround is to enclose the input field within a parent element that has a customized border style and then use a trick with :-webkit-autofill to preserve the white background color.

In this solution, I replaced the .contain class with a .gradien class and updated the type attribute from name to text (as there is no type called name).

To maintain the gradient effect even with autocomplete enabled, all input and textarea elements need to be wrapped in a parent element with a .gradient class applied to it.

.half {
  width: 50%;
  margin-left: auto;
  margin-right: auto;
}

.gradient {
  background-image: linear-gradient(white, white), radial-gradient(circle at top right, #006699, #9900CC);
  background-origin: border-box;
  background-clip: padding-box, border-box;
  border: solid 5px transparent;
  border-radius: 30px;
  margin-bottom: 10px;
  overflow: hidden;
}

input[type=text] {
  width: 100%;
  padding: 15px;
  margin: 0 !important;
  display: inline-block;
  margin-bottom: 10px;
  outline: none;
  box-sizing: border-box;
  border: none;
  background: #fff;
  font-family: 'Roboto', sans-serif;
  font-size: 15px;
  box-sizing: border-box;
}

/* Customizing Autocomplete styles in Chrome*/

input[type=text]:-webkit-autofill,
input[type=text]:-webkit-autofill:hover,
input[type=text]:-webkit-autofill:focus {
  /* prevent blue highlight */
  -webkit-box-shadow: 0 0 0px 1000px #fff inset;
}

textarea {
  width: 100%;
  min-width: 100%;
  max-width: 100%;
  min-height: 200px;
  max-height: 200px;
  padding: 15px;
  resize: none;
  display: inline-block;
  outline: none;
  border: none;
  box-sizing: border-box;
  font-family: 'Roboto', sans-serif;
  font-size: 15px;
  border-radius: 30px;
  box-sizing: border-box;
}
<div class="half">
  <form method="post" name="submitted" action="submitted" autocomplete="off">
    <div class="gradient"><input type="text" id="forename" name="forename" placeholder="Forename"></div>
    <div class="gradient">
      <textarea></textarea>
    </div>
    <br>
    <input type="submit" name="submit" id="submit" value="Contact Me" required="">
  </form>
</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

The use of WebSockets in conjunction with text encoding techniques

After reviewing the material, I came across this information: The WebSocket API allows for the use of a DOMString object, which is transmitted in UTF-8 format, or it can also accept an ArrayBuffer, ArrayBufferView, or Blob objects for binary data transf ...

Encountering a problem with utilizing the equalTo() method in Firebase Realtime Database in a React

I'm having trouble randomizing and querying a specific node in my database based on the ShopNo When I use equalTo, I can't seem to retrieve the desired node. Instead, I'm only getting a randomized value based on the total number of Shop ent ...

Troubleshooting: Bootstrap interfering with external CSS file and causing errors

Attempting to utilize Bootstrap for the design of my website, I encountered an issue when trying to implement an external CSS file named "mycss.css". Unfortunately, it seems to not be functioning properly at all. Both the file, "mycss.css" and index.php ar ...

There seems to be a problem with the sorting functionality on the table in React JS,

My React table is functioning well with all columns except for the country name column. I double-checked the API and everything seems to be in order, but I'm stuck on how to troubleshoot this issue. const Table = () => { const[country, setCount ...

HTML: Mark the chosen hyperlink or tag

In my HTML page, I am looking to keep the link selected when it is clicked on. Here is the initial HTML code: <table class="main-dev"> <tr> <td> <a class='titleForm' style="cursor:pointer"> ...

Bring icons.js component into react via import and export

I have a file called icons.js where I've imported all icons from the react-icons package. How can I share this file so that other components can access it? This is what my icons.js file looks like: import {BiStore} from 'react-icons/bi'; i ...

Fetching locales asynchronously in nuxt.js using i18n and axios: A step-by-step guide

I am facing an issue with getting the location asynchronously. Whenever I try to implement my code, it results in a "Maximum call stack size exceeded" error. How can I resolve this issue? Previously, I attempted to retrieve the location by using the axios ...

Sending a POST request to a server using NodeJS with an array as the value for

Just to clarify, I am limited to using default modules in node version 9.x.x and cannot use the express module. I have a form where users can input basic information (name, birthday, email), and multiple user entries can be posted simultaneously. The serve ...

Techniques for breaking down large CSS files into modules and combining multiple smaller CSS files

My website's CSS file is currently massive, containing site-wide selectors in a file named Mondo.css. While this setup has been effective for ensuring users only need to download the file once, I've recently developed a widget that requires its o ...

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 ...

Utilizing AngularJS to Implement Gradient Effects Using the ng-style Directive

Having trouble setting gradients using the angular js ng-style directive. I can successfully set normal colors using the code below: <span ng-style="{'background-color': slidercolor}">works</span> However, when trying to set a gradi ...

Guide to creating the shared section of two wheels with CanvasRenderingContext2D

Is it possible to dynamically draw the shared area of two circular shapes using JavaScript and CanvasRenderingContext2D? My ultimate goal is to be able to adjust the size of the shape, ranging from a complete circle to a mere point. The desired outcome is ...

Tips for writing PHP code that correctly displays a user's username post-login

Can anyone assist me in creating a code that can show a user's username after they log in? I have been referring to some tutorials to guide me through this process, so I apologize for any mistakes I may have made. I am still fairly new to coding. Pro ...

Guide on Triggering a Custom Popup Message upon a Server Action in Next.js

Hey there, I'm currently facing some difficulties in finding the proper way to trigger a toast notification after successfully mutating data using server actions in Nextjs 13. The toast component I'm working with is specifically designed for clie ...

Guide on sending a request to an API and displaying the retrieved information within the same Express application

I recently developed a basic express app with API and JWT authentication. I am now attempting to enhance the app by incorporating page rendering through my existing /api/.. routes. However, I am facing challenges in this process. app.use('/', en ...

Customizing hover effects to change the color of stars in a rating system

I am facing a challenging issue with my star rating system. Initially, I receive stars from CMS and assign them unique IDs. When the page is not rated, it appears as follows: <div class="rated"> <a class="star" href="#" onclick="star(1,6226, ...

Does the zoom value in the HTML file adjust when I zoom in or out on the Google Map?

I'm uncertain if my question is sufficiently clear. Here's my dilemma: I've been utilizing the gmplot module in Python and I'm interested in adjusting the grids to be scalable based on the zoom level of the Google Map. However, being u ...

Tips for combining all filtered items into a single state variable

I have an array of objects containing user data stored in a state variable and a table where these users are displayed. There is a search field where users can type names to search through the list. My question is, when a user types a name, I want to sea ...

What could be causing my page to appear off-center?

Hey there! I'm still learning the ropes, but I could really use a hand with this issue: So, while I was playing around with HTML and CSS, I wanted to create a page with a fixed size that would be perfectly centered on the screen. My approach was to p ...

Allow Vue to handle the registration of the datepicker event

Is there a way to notify Vue when the datepicker changes the selected date? new Vue({ el: '#app', data: { termin: '' }, computed: { }, methods: { } }) This is just an input field: <div id="app"> <div c ...