Flashing border of Bootstrap input occurs when clicking away from a modified input that is in focus

In my form, I have implemented a custom floating placeholder/label for an input field. I wanted to customize the focus behavior by removing shadow and modifying the borders. The current code is almost working as intended:

.paddings{
  padding: 5rem;
}
input.my-input:focus{
  box-shadow: none;
  border: thin solid rgba(0, 100, 173, 0.5);
  border-top: none;
}
.floating-label{
  color: rgb(80 80 80);
  pointer-events: none;
  position: absolute;
  left: 2.5rem;
  top: 0.5rem;
  transition: 0.2s ease all;
}
input:focus ~ .floating-label{
  color: rgb(40 40 40);
  font-size: 0.85rem;
  top: -0.65rem;
  left: 2rem;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="45272a2a31363137243505766b766b72">[email protected]</a>/dist/css/bootstrap.min.css">
<div class="row paddings">
  <div class="col-md-12">
    <div>
      <input class="form-control my-input" type="text"> 
      <span class="floating-label">Search</span>
    </div>
  </div>
</div>

While everything works well when focusing on the element, there is a sudden flash of black top border when unfocusing. This unexpected behavior is perplexing me.

I attempted to eliminate the transition effect but it persists. How can I smoothly transition back to the original light grey color without the annoying black border flashing in between?

Answer №1

The reason for this issue is the border-top property set on input.my-input:focus to none. To resolve it, you can remove that and adjust the negative margin on input:focus ~ .floating-label:

Update: As per OP's comment - changing the color of the border-top property will fix the problem:

.margins{
  margin: 3rem;
}
input.my-input:focus {
  box-shadow: none;
  border: thin solid rgba(0, 100, 173, 0.5);
  border-top: whitesmoke;
  
}
.floating-label{
  color: rgb(80 80 80);
  pointer-events: none;
  position: absolute;
  left: 2.5rem;
  top: 0.5rem;
  transition: 0.2s ease all;
}
input:focus ~ .floating-label {
  color: rgb(40 40 40);
  font-size: 0.85rem;
  top: -0.65rem;
  left: 2rem;
}
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0b2bfbfa4a3a4a2b1a090e3fee3fee7">[email protected]</a>/dist/css/bootstrap.min.css">
<div class="row margins">
  <div class="col-md-12">
    <div>
      <input class="form-control my-input" type="text"> 
      <span class="floating-label">Enter text here</span>
    </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

Adjust the size of the password input characters without changing the appearance of the placeholder

Is there a way to enlarge the font size of an HTML password input without changing the placeholder text as well? Specifically, I am looking to increase the size of the password symbols (bullets). I attempted to adjust the font-size property of input[type= ...

What could be causing my PrimeReact dropdown component to ignore the custom class styles?

Within my Project, I am utilizing multiple Prime React dropdown components and I am aiming to customize one of them with a unique style. In my CSS, I have established global styles to overwrite the default settings for all the dropdowns. However, when tryi ...

Transient Flash of a jQuery Dropdown Menu

I'm currently developing a jQuery/CSS dropdown menu for a website, and everything is functioning well except for one issue. When navigating between sub-menu items, the text color of the selected main menu item briefly changes because of the CSS border ...

initiate an animated sequence upon the initialization of the Angular server

Is there a way to launch a Netflix animation after my server has started without success using setTimeout? I don't want to share the lengthy HTML and CSS code. You can view the code for the animation in question by visiting: https://codepen.io/claudi ...

Python script for automating captcha scraping

I recently started learning about web scraping and decided to try scraping the website www.mediamarkt.de using Python and BeautifulSoup. However, whenever I make a request to the website using the following commands page = requests.get(url, headers=headers ...

Sorry, Laravel 8 module form error: The POST request is not allowed on this route. Only GET and HEAD methods are supported

**I'm having trouble understanding routes and how to specify the path. ** web.php - this route is located inside my module named events <?php use Illuminate\Support\Facades\Route; Route::prefix('event')->group(fu ...

Is it possible to integrate a Neo4j Graph Visualization running on a virtual machine into my flask user interface?

My current setup involves running Neo4j on an Azure Virtual Machine and accessing the graph visualization through a web browser. In addition, I have developed a UI using Python with Flask that is currently running locally. I am interested in embedding th ...

Experience the ultimate in slider automation with the cutting-edge power of

Here is an example of a website plugin I used on my site. You can check it out by clicking here. However, I'm having trouble automating the events that occur when the item slider is clicked. I would like to make these events happen automatically with ...

What methods can be used to accomplish this effect using CSS and/or Javascript?

Is there a way to achieve the desired effect using just a single line of text and CSS, instead of multiple heading tags and a CSS class like shown in the image below? Current Code : <h2 class="heading">Hi guys, How can i achieve this effect using j ...

Adding the "input-invalid" class to the input doesn't take effect until I click outside of the input field

When the zipcode field is updated, an ajax call is made. If there are no zipcodes available, I want to mark it as invalid by adding the "input-invalid" class. However, the red border validation only appears when clicking outside of the input field. Is ther ...

Regular expression for validating passwords will be disregarded

I crafted this javascript and html code to validate the username and password input. Strangely, the regular expression for the password is not being acknowledged. function checkDetails() { var uname = document.getElementById("uname").value; var pass ...

Arrange the radio buttons vertically, one beneath the other

Is there a way to align radio buttons vertically instead of horizontally like this? Sex (button)Male (button) Female No matter what I try, it ends up looking like this ...

Implementing the 'active' class on a hyperlink in CodeIgniter: A step-by-step guide

My template is divided into three sections: header, footer, and content. The main menu links are located in the header section. I am trying to apply a CSS class 'active' to the hyperlink that is selected. I have written jQuery code to achieve thi ...

Folding into itself lies another folding

While attempting to nest a collapse area inside another collapse, I encountered an issue. Upon clicking to open the first collapse, it functions perfectly. However, when trying to open the second collapse (nested within the first one), it inadvertently cl ...

Transforming traditional HTML table layout to modern div structure

We are currently in the process of transitioning old pages from our previous website structure, which used tables, to our new layout based on DIVs. Our website is structured using a PHP include system with separate components for the header, body, and foot ...

Get rid of the white border surrounding the object tag

Help needed in removing a thin white border around the object tag. Below is the code snippet and what has been attempted: .hr-ob { background-color: #003262; width: 50px; height: 10px; border: none; outline: none; ...

An anchor-shaped name tag with a touch of flair

I stumbled upon this unique anchor name design on the website Does anyone here know how to create something similar? What is that style called? ...

What is causing the elements on the screen to not occupy the entire screen?

My web-app on react is not displaying full-screen, even though there are very few elements on the page. https://i.sstatic.net/RYc6D.jpg https://i.sstatic.net/yhqey.jpg https://i.sstatic.net/uKuLD.jpg Css: html { height: 100%; width: 100%; } * { margin: ...

The Width of Material UI Divider

Currently seeking a method to increase the line thickness of the Material UI Divider, whether by stretching horizontal lines vertically or stretching vertical lines horizontally. I have reviewed the documentation for Material UI v5 on https://mui.com/mate ...

Differences in rendering with Google Chrome when zooming in or out

After creating some code, I observed a peculiar issue. At 500% zoom, the DOWNLOAD button aligns perfectly with the left wall without any gap. However, upon reducing the zoom to 250%, a green background segment becomes visible. To witness this anomaly, refe ...