Is there a way to add default text to a number input field that already has a value?

My current HTML input code is as follows:

<input type="number" min="4" max="100" step="1" name="myInput" value="33">

The value of this input field is being populated from a cookie or storage that was set on a previous screen where the user provided a party size.

However, from a user experience standpoint, it's not immediately clear what "33" represents on this screen. Since I am dynamically populating the input, using placeholder text isn't an option. This has led me to explore ways in which I can somehow inject the word "People" after the numerical value.

I do prefer the clean look of the UI without visible form labels, so I would like to avoid adding them if possible.

This is the current state of affairs: https://i.sstatic.net/rKP0F.png

And this is the desired effect (highlighted in red): https://i.sstatic.net/J17OX.jpg

It may be simply achieved through a background image, but I want to ensure the spacing remains neat and precise. Any suggestions or advice would be greatly appreciated! Thank you!

Answer №1

Here is a suggestion that might set you on the right path:

HTML:

<label data-placeholder="people">
  <input type="number" min="4" max="100" step="1" name="myInput" value="33">
</label>

SCSS:

LABEL {
    position: relative;

    &:after {
        content: attr(data-placeholder);
        position: absolute;
        color: red;
        z-index: 1;
        top: 1em;
        right: 1em;
    }

    INPUT {
        width: 200px;
        box-sizing: border-box;
        padding-right: 5em;
    }
}

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 value of an element within an array changes automatically`

In my current setup, I have a traditional array where each element represents an HTML element. The issue arises when I manipulate these elements within the array; any changes made to the HTML element also reflect in the array automatically. However, I pref ...

How to Insert a Background Image into Advanced Custom Fields (ACF) using CSS

Hey there, I'm facing a bit of a challenge with this particular section. In the past, I've only included ACF PHP within HTML when the background image was directly in the HTML code. Now, however, I have two shapes specified in my CSS using pseudo ...

Arranging divs precisely while rotating a Bootstrap Thumbnail

I've been experimenting with creating a "css3 on hover flip" effect for bootstrap thumbnails. It works perfectly fine on simple divs (check it out here) Here's the main CSS3 code I'm using: .front{ position:absolute; transform:pers ...

Container slide-show fill error

I'm attempting to create a slide show with an overlapping caption that appears when hovering over the container or image. The image needs to fit exactly inside the container so no scroll bar is shown and the border radius is correct. I managed to achi ...

Ajax facilitates the loading of multiple containers

My goal is to utilize Ajax to load dynamic content. The process starts with a list of countries. When a country is selected, the cities in that country are displayed, followed by suburbs, companies, branches, and eventually branch details: Countries --> ...

Breaking HTML attribute values into separate lines will make the code more organized and easier

Is it possible to format HTML attribute values so they can span across multiple lines? Essentially, I'm wondering if there is a way to include line breaks within a regular typed HTML attribute value. For instance, in the functional code snippet below ...

Creating a wide-ranging megamenu with CSS only

I am interested in creating a full-width Mega menu. Here is the link for reference: http://codepen.io/tanmoy911/pen/KzjVdq My CSS code follows a 12 column grid system. .fui-navbar{list-style-type:none;margin:0;padding:0;overflow:hidden} .fui-navbar li{fl ...

What is the most efficient way to implement hiding/showing elements, adding/removing classes, and optimizing code in jQuery?

Looking for a more elegant solution to toggle classes on a div when clicking a button? Current code logic: jQuery(document).ready(function($) { // Removing/adding classes to show/hide div elements on button click // More efficient w ...

Display hidden text upon clicking using React Material UI Typography

I have a situation where I need to display text in Typography rows, but if the text is too long to fit into 2 rows, ellipsis are displayed at the end. However, I would like to show the full text when the user clicks on the element. I am attempting to chang ...

Exploring Data in ASP.NET Resource Files

I currently have an HTML file located in Resource1.resx. My goal is to retrieve the content of this HTML file using a StreamReader. What steps should I take to achieve this? Here is the HTML file content: <html> <body> <table> < ...

What is the best way to transfer Javascript variables from an HTML template to a view function in Django?

Currently, I am developing a website using Django. One of the features I'm working on is a form in my HTML page that includes a textbox for users to input their name with a label "Enter your name". Underneath the textbox, there is a submit button. ...

What could be the reason for the d-flex class in bootstraps preventing my div from expanding to 100% width?

I have a div where I need to display two elements next to each other: a search input field and the corresponding submit button. My attempt so far was to achieve this using the following code: <link rel="stylesheet" href="https://maxcdn.bootstrapcdn. ...

Using multiple foreach loops within each other

After struggling with this issue for days, I've decided to seek some assistance :) I'm currently working on a project management tool that includes an edit-page where admins can modify project members and their roles within the project. My goal ...

How can I create a clickable <div> element containing multiple links and trigger only one action?

Within my code, there is a <div> element that has been made clickable. Upon clicking this <div>, the height and text expand using the jQuery function $(div).animate();. While this functionality works as intended, I am encountering a slight issu ...

Using custom or external fonts icons in Chrome Packaged Apps involves the following steps:

Seeking to enhance the appearance of my Chrome Packaged App built in AngularDart, I searched for external icons online but came up empty-handed. Despite attempting various strategies and implementing the workaround provided below, I have been unable to ach ...

Harvest information from various files

I have a collection of 278 Html files containing essays written by various students. Each file includes the student's ID, first name, and last name in this format: <p>Student ID: 000000</p> <p>First Name: John</p> <p>Las ...

CSS Tutorial: Creating a Dynamic Gradient Bar

I am looking to create a dynamic colored bar with a moving color gradient effect. Without using JavaScript, I want to achieve this effect using CSS 3 properties such as gradients and animations. This is a snippet of what I have tried so far: HTML: <b ...

What is the best way to add a value to the value attribute of a div using JavaScript?

Is there a way to insert a value into the value attribute of a div using Internet Explorer 9? I have attempted various JavaScript functions, but so far I can only modify the content inside the div and not the value attribute itself. <div id="mydiv" val ...

How should attributes be passed to the li element properly?

I am trying to transfer values from the database to the <li> tag. Can someone confirm if the approach below is valid and the proper way to do it? <li id='$current_row["RA_SUB_ID"]' component_name='$current_row["RA_SUB_NAME"]' ...

What is the best method for implementing a "night mode" feature using CSS?

I have a vision for a website that offers both a 'day' and 'night mode', providing users with a light and dark version of the site. However, I'm struggling to find the best way to achieve this. Initially, I attempted creating two ...