Issue with label visibility for hidden date input in Chrome

When setting up a date input with a placeholder, I encountered an issue. To hide the actual input field while displaying the label, I used the following code:

    document.querySelector("#date").onchange = (e) => {
      document.querySelector("#datelabel").innerHTML = e.target.value;
    }
    #datelabel {
        padding: 16px;
        border-radius: 15px;
        border: 2px solid rgba(0, 0, 0, 0.8);
        outline: none;
        font-size: 20px;
        transition: .2s;
        width: 200px;
        display: block;
    }
    <input type="date" name="date" id="date" style="display:none;">
    <label class="input" for="date" style="color:var(--text);" id="datelabel">Date</label>

The issue arose on Chrome but not on Firefox. Removing the display property made it work, but I wanted to keep the input hidden. Various attempts like setting height and width to 0, using overflow: hidden, or adjusting paddings and margins caused layout problems.

After some exploration, I found a working solution by hiding the input differently:

position: absolute;
visibility: hidden;

With this approach, the functionality works properly across different browsers.

Answer №1

Give this a shot, it definitely does the job

input {
    padding: 16px;
    border-radius: 15px;
    border: 2px solid rgba(0, 0, 0, 0.8);
    outline: none;
    font-size: 20px;
    transition: .2s;
    width: 200px;
    display: block;
}
::placeholder {
  color:black;
  font-size: 25px;
  
}
<input type="text" name="date" id="date" id="datelabel" style="display:block;" placeholder="Date">

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

Disabling caching in bootstrap tabs for loading ajax content

My goal is to make bootstrap tabs load content through ajax queries. While this process is straightforward with Jquery tabs, which default to loading content via ajax query, it seems to be a different case for bootstrap. As such, I have come across the fo ...

Show dynamic HTML Dropdowns with nested JSON data

I've been racking my brains trying to implement this specific functionality in the UI using a combination of HTML5, Bootstrap, CSS, and JavaScript. My goal is to create dropdown menus in the UI by parsing JSON input data. Please Note: The keys withi ...

Accessing video durations in Angular 2

Can anyone help me with retrieving the video duration from a list of videos displayed in a table? I attempted to access it using @ViewChildren and succeeded until encountering one obstacle. Although I was able to obtain the query list, when attempting to a ...

How can I get electron to interact with sqlite3 databases?

I've exhausted all my options and still can't get it to function. This error message keeps popping up: https://i.stack.imgur.com/D5Oyn.png { "name": "test", "version": "1.0.0", "description": "test", "main": "main.js", "scripts": { ...

Manage form submission seamlessly without redirecting. Capture information without needing to prevent the default action, then proceed with redirection. Avoid redirecting when using preventDefault, but be aware that data may not

Currently stuck in a tricky situation. I've implemented a custom form submission to prevent redirecting when an express route is triggered by form submission. However, the issue arises when I lose the data being sent without redirection. document.get ...

Preventing box shadows from blending together

I'm struggling with a design issue on my site where I have four divs in the center, each represented by a box with a box-shadow. Unfortunately, the colors of the shadows are getting mixed up and creating an unwanted effect. https://i.sstatic.net/NdAUB ...

Tips for creating a seamless merge from background color to a pristine white hue

Seeking a seamless transition from the background color to white at the top and bottom of the box, similar to the example screenshot. Current look: The top and bottom of the box are filled with the background color until the edge https://i.stack.imgur.com ...

When running "npx react-native init client" on Android, the command fails due to the error message stating that tools.jar could not be found. This issue occurs specifically with React

Device: Windows 10 NodeJS Version: v13.8.0 React Native Version: 0.62.2 React Version: "16.11.0" The issue persists even with the typescript template. Upon executing the command npm run android, I encountered the following logs: info Running je ...

How can I disable a checkbox in AngularJS?

Is there a way to automatically disable a checkbox when selecting an item from the combo box? For example, if "ABONE" is selected, Angular should disable the ABONE checkbox. Note (for example): DefinitionType: ABONE https://i.sstatic.net/vcZpR.png ...

Utilizing jQuery to effortlessly generate parent and child elements in a single function call

Is it possible to create multiple elements with the same function? Currently, I am able to split a number of list items like this: <ul class="dropdown-menu"> <li>Stuff</li> <li>Stuff</li> <li>Stuff</li> ...

Checkbox does not appear in Internet Explorer

I'm sorry, but I have never encountered this issue before. It seems that my checkboxes are not showing up in Internet Explorer but they do in Firefox. I am unsure why this is happening as I don't know of another way to create checkboxes. &l ...

What is the best way to prompt my bot to send a follow-up message once a user responds to a query?

I'm currently developing a system where a bot asks users questions, clears the messages after receiving their replies, and then proceeds to ask another question in a loop until all questions are answered. However, I'm facing an issue where the b ...

Preventing pageup/pagedown in Vuetify slider: Tips and tricks

I am currently using Vuetify 2.6 and have integrated a v-slider into my project. Whenever the user interacts with this slider, it gains focus. However, I have assigned PageUp and PageDown keys to other functions on the page and would like them to continue ...

Passing the URL of a cropped image as a property in React

Currently, I am working on implementing a cropper using (react-image-crop) following a tutorial on YouTube. The cropper code looks like this: export const Cropper = (base64Image) => { const [src, selectFile] = useState(null); const handleFil ...

Material design for Angular applications - Angular Material is

Recently, I decided to explore the world of Angular and its accompanying libraries - angular-material, angular-aria, and angular-animate. I'm eager to experiment with this new styling technique, but it seems like I've hit a roadblock right at the ...

Utilize jQuery to trigger a color change upon clicking and modify the background

I am currently working on a fairly simple task where I aim to change the color of the #new-quote button upon clicking it using jQuery. Eventually, my plan is to have every non-whitespace section of the webpage change to the same color when clicked. However ...

The color of the navbar-toggler-icon in Bootstrap cannot be altered

While working on customizing my Bootstrap 5 navbar, I encountered an issue with changing the color of the navbar-toggler-icon. The preset colors, navbar-light and navbar-dark, didn't align with my theme, so I attempted to change the color to pure whit ...

Inspect every div and perform an action if the criteria are met

I need assistance with adding text inside a specific div based on certain conditions. Currently, all the div elements are being populated with the added text. Please review my code for more clarity on what I am trying to achieve. Can you suggest the most e ...

css Apply styles to form controls only if they are not empty

Utilizing an angularjs form, I have customized the following example to fit my code: .my-5 { margin:100px; } .form-group { position: relative; margin-bottom: 1.5rem; } .form-control-placeholder { position: a ...

The scaling of SVG images within Raphaël.js appears to be inaccurate

I have an .svg file that I need to convert into Raphaël.js format. The image itself looks great, displaying everything accurately. When attempting to convert it using the website , I encountered an issue where the viewports were not being understood prop ...