Labels appear to float and overlap with input fields that already contain data

Having trouble with input values overlapping the label when pre-filled?

https://i.sstatic.net/ECuwr.jpg

If you want to ensure that the label does not overlap when the input is pre-filled and also have a smooth transition effect when the user removes the value and changes focus, here's the CSS code:

.input-float {
    font-size: 14px;
    padding: 10px 10px 10px 5px;
    display: block;
    width: 100%;
    border: none;
    border-bottom: 1px solid #757575;
}
.input-float:focus {
    outline:none;
}

/* LABEL ======================================= */
.label-float {
    color: #999;
    font-size: 14px;
    font-weight: normal;
    position: absolute;
    pointer-events: none;
    left: 5px;
    top: 10px;
    transition: 0.2s ease all;
}

/* active state */
.input-float:focus ~ .label-float {
    top:-20px;
    font-size: 14px;
    color: #5264AE;
}

/* BOTTOM BARS ================================= */
.bar {
    position: relative;
    display: block;
    width: 100%;
}
.bar:before,
.bar:after {
    content: '';
    height: 2px;
    width: 0;
    bottom: 1px;
    position: absolute;
    background: #5264AE;
    transition: 0.2s ease all;
}
.bar:before {
    left: 50%;
}
.bar:after {
    right: 50%;
}

/* active state */
.input-float:focus ~ .bar:before,
.input-float:focus ~ .bar:after {
    width: 50%;
}

/* HIGHLIGHTER ================================== */
.highlight {
    position: absolute;
    height: 60%;
    width: 100px;
    top: 25%;
    left: 0;
    pointer-events: none;
    opacity: 0.5;
}

/* active state */
.input-float:focus ~ .highlight {
    -webkit-animation: inputHighlighter 0.3s ease;
    animation: inputHighlighter 0.3s ease;
}

/* ANIMATIONS ================ */
@-webk...

Answer №1

Employ JavaScript to initiate a modification

$("#id").val("updated value").trigger("change");

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

Dim the background for all elements except for one

Seeking a way to create a dimmed-background effect by adjusting the opacity of all elements on the page except for one specific element. I've experimented with using the :not() selector as well as jQuery selectors to exclude certain elements, but have ...

The form does not support inserting all values through AJAX. We may need to implement a QUERY to handle this

Can someone help me find the issue in my code? I have checked the back end and can't seem to identify the logic error. The form submission shows as successful but does not insert the values into the database. I'm still learning how to use ajax, s ...

Creating a Scrolling Element in CSS Without Displaying a Scrollbar

Find the visuals and code on JSbin here. Looking to create a left sidebar that is full height with a fixed position, yet have its content accessible without scrollbars and no need for overflow: scroll. I'm hoping to achieve this in CSS only, without ...

I am encountering a 'Cannot GET /index.html' error when running my Node.js and Express application, even though I do not have an index.html file

I'm puzzled by the error I'm encountering. Everything runs smoothly on my local machine, but when I try running it on Linux, this error pops up. I've already created ejs files and included all necessary components. Additionally, there is no ...

Column overflowing from row in Bootstrap grid on smaller screens

Is there a way to rearrange the display order of my Hello-div-2 and Hello-div-3 on small screens? Currently, the sequence is Hello-div-1, Hello-div-2, Hello-div-3, Hello-div-4. It needs to be Hello-div-1, Hello-div-3, Hello-div-2, Hello-div-4. ...

Tips for avoiding duplicate ids in dynamic divs

I have been working on dynamically creating divs, and while my method is functioning properly, I am encountering an issue with id duplication. Due to restrictions in this scenario, I am only allowed to create 4 additional divs. Below you can find the relev ...

Select options with disabled sorting feature

Is there a way to use CSS to sort disabled options in a select element? I would like all disabled options to appear at the bottom, with enabled options at the top. In the screenshot attached, you can see that enabled options are black and disabled options ...

Tips for stopping table column width growth when an icon is inserted into a cell dynamically

In the table I have, the header is clickable and when clicked, it triggers sorting. Clicking on the header title adds an icon (ascending or descending) to the right of the title, causing the column width to increase based on the size of the icon. Refer to ...

What is the best way to skip through a video quickly in Selenium with Python?

Up to this point, I have successfully used the code below to play a video. However, I am now looking to scrub the video to the end so that I can finish the current season and proceed to the next page. Is there a way to quickly end the video once it start ...

Issue with Internet Explorer's svg text alignment and sizing when text-anchor and textLength attributes are applied

After observing the webpage below, I have noticed that it does not display correctly in IE 11, although it works perfectly in Google Chrome. The text elements marked with "text-anchor:end" in the example below are not properly aligned with the end of the ...

The div is refusing to align to the left within the same row

I need assistance in creating a footer layout with an h3 and two div elements, all floated to the right with a percentage margin. The issue I'm facing is that the second div element (div2) is not floating to the left as expected but instead aligns be ...

The string obtained from input.getAttribute('value') is lacking one character

While developing e2e-tests for an angular application, I encountered a puzzling issue. When trying to retrieve the value from an using the .getAttribute('value') method, I noticed that a single character was missing. Checking the HTML properties ...

Using Selenium and PhantomJS for web scraping to retrieve information on product details

As a beginner in web scraping with Python, I am currently working on extracting product details from a webpage using Selenium and PhantomJS. However, I am facing a challenge as the page does not display the rendered HTML when I try to access it using "driv ...

In Angular 4, the Bootstrap modal now only opens after a double click instead of opening on the first click

Working on an eCommerce application, there is a cart icon that triggers a modal screen displaying user-selected product data when clicked. However, the issue I'm facing is that upon initial page load, the modal screen opens only after double-clicking; ...

Troubles with Marquee Element

Being a beginner in the world of html and css, I have encountered an issue while creating a responsive web page. At the top of my page, there is a text within a div which gets cut off from the right side as I decrease the browser width. Initially, I cons ...

The AddClass function fails to function properly after an ajax form is submitted

I am facing a challenge in setting up validation for my ajax form. My goal is to have a red border appear around the input field if it is submitted empty. Unfortunately, when I try to use addClass(), it does not seem to have any effect. The alert message ...

What are your thoughts on using image maps with CSS?

My images are also links, and the code looks like this: <a href="../www.google.com"><img src="pages/squirrely.png" /></a> While they function properly as links, I want them to only be clickable if you click on the central part of the im ...

The images on the Shopify platform are becoming increasingly fuzzy

I'm facing an issue where the images I add to my Shopify site using the Brooklyn theme appear blurry unless resized to a small scale. The dimensions of the images are 1748 x 1240 at 300dpi. My intention is to implement a JQuery image slider (lightsli ...

Changing ch to Px in CSS

Important Notes: I have exhaustively explored all the questions and answers related to this particular topic. The question I have is very straightforward: How many pixels are equivalent to 1 character? Here's a sample of my code - code Related Sear ...

Creating a tab resizing effect similar to Chrome using only CSS

I am attempting to design tabs that can dynamically resize similar to how Chrome tabs behave. However, I am uncertain if achieving this functionality is possible without relying on JavaScript. Browser compatibility is not a concern for me; my main goal is ...