An asterisk is compulsory within the input field

Is there a way to place a red asterisk inside an input field on the far right side? My form doesn't have enough space to include an asterisk separately, and inserting it in an unconventional manner would look odd. Below is the CSS I am using for my input fields:

input {
    padding: 15px;
    border: 1px solid #ccc;
    border-radius: 3px;
    margin-bottom: 10px;
    box-sizing: border-box;
    font-family: montserrat;
    color: #2C3E50;
    font-size: 13px;
}

Does anyone know of a solution to achieve this? Thank you.

Answer №1

When working with Bootstrap, you can take advantage of the "input-group-addon" class to achieve the functionality you are describing. If Bootstrap is not being used in your project, consider incorporating the CSS for that class if it aligns with your project's vision. You can find an example of this class being utilized here: http://getbootstrap.com/css/#forms

Answer №2

To prevent using a before or after for input control, the solution is to wrap the input control with a div (set it as inline-block) and utilize css "after" to position the "*"

#container {
  position: relative;
  display: inline-block;
  z-index: 1;
}
#container input {
  padding-right: 14px;
}
#container:after {
  content: "*";
  position: absolute;
  right: 5px;
  top: +3px;
  color: red;
  z-index: 5;
}
<div id="container">
  <input type="text" />
</div>

Answer №3

If you want to incorporate Glyphicons into your Bootstrap 3 project, you can follow these steps:

.requiredFieldWrapper::after 
{
    font-family: 'Glyphicons Halflings';
    content: '*';
    position: absolute;
    top:2px;
    bottom: 0;
    right: 17px;
    font-size: 10px;
    color: red;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<br>
<br>
<div class="col-xs-10 requiredFieldWrapper">
 <input class="form-control" type="text" autocomplete="off" required>
</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

instead of downloading the file, click on the provided download link to open it directly

Currently, I am utilizing Python Selenium to web scrape images in Chrome. To complete the download of these images, I generate download links using the subsequent code snippet: script_js = 'var imageURL = document.getElementsByTagName("{select_ta ...

html body extends beyond the negative position of the element

If you visit my website at this link, try resizing the window until the responsive design kicks in. Then, click on the "right" button at the top of the page. You'll notice that the right sidebar disappears and reappears, but when it disappears, the ba ...

Transferring a PHP variable via a URL

I'm having a bit of difficulty passing the value of a variable named artID as part of an href link. It seems like where I place this variable impacts whether or not the link actually works. If it's outside of the PHP tags, the link breaks, but if ...

Tips for removing CSS and Javascript code from a website's source code

After implementing the Slicknav Menu plugin on my website, I noticed that a portion of the plugin's CSS and script code is visible when inspecting the source code of the main page: <head> ... <style id='slicknavcss-inline-css&apo ...

Arrange SVGs using CSS in a grid with offsets

My current project involves creating a background using SVGs in React. I'm looking for an easy CSS method to arrange these icons in a grid, possibly with an offset for the second row. I also need the width of the icons to be dynamic so that they adj ...

Masterful Text Pairing: Using Zen Coding Techniques for Crafting Intricate Nesting Structures

Result : <div id="header"></div> <div id="body"> <hello> <world></world> </hello> </div> Mapping to : div#header+div#body>hello>world Which command should be used to achieve the desi ...

An error in syntax is being triggered by the Php file being accessed through the <script src="list.php"></script>

We're facing an unusual problem with our online ordering platform script that we purchased a few months ago. It had been functioning perfectly for several months, but now we're encountering an issue! The website page is not loading, and when we c ...

Get the HTML code of a webpage that incorporates JavaScript into its design

Currently, I am attempting to retrieve the HTML code of a webpage using wget --load-cookies=cookies.txt However, I seem to only be able to access the main page's HTML without the content generated after JavaScript execution. I am hoping to retrieve ...

What is the process for incorporating an additional input in HTML as you write?

I am looking to create a form with 4 input boxes similar to the layout below: <input type="text" name="txtName" value="Text 1" id="txt" /> <input type="text" name="txtName2" value="Text 2" id="txt" /> <input type="text" name="txtName3" valu ...

What is the process for creating a global variable in JavaScript?

Having trouble changing the value of "invocation_num" within a loop? I attempted to modify it as follows, but ended up with an undefined value. Any help would be greatly appreciated. $(document).on("click", '.favoret', function(){ document ...

Is there a way to modify the text within a hyperlink using jQuery?

Here is the link HTML code snippet: <a href="#" onclick="run(1); return false;" class="link" title="Remove item">[x]</a> I am looking to modify this using jQuery to display like this: <a href="#" onclick="run(1); return false;" class= ...

Trouble getting BS4 find_all to recognize the mini_card-title class on Genius Lyrics website

I am currently working on a project where I am trying to extract the title of a song from the genius lyrics' song search. Despite trying to use .find_all("div", class_="mini_card-title") to retrieve the song name, I have found that it does not work as ...

Offering various language options on a website determined by the URL

I've been contemplating how to add multi-language support to my personal website, which I developed using ExpressJS and NodeJS with EJS as the template engine. Currently, the website is only available in English, but I want to add a German version as ...

Emblem pointing towards the header

Seeking advice for modifying arrow function: <script> $(window).scroll(function() { var pxFromBottom = 1300; if ($(window).scrollTop() + $(window).height() > $(document).height() - pxFromBottom) { $('#nagore').fa ...

Notifying individuals of a file's unavailability using HTML tags

I recently created an API that is designed to deliver files to the frontend. Here is how it looks: <a href="downloadFile.aspx?file=token" download target="_blank"> The file download functionality is working fine. However, the issue arises when the ...

Is there a way to ensure that a child mimics the behavior of its parent when adjusting the opacity and visibility properties of both elements?

Apologies for the ambiguous title, as I am struggling to accurately convey the issue I am encountering. To clarify the problem, I have created a jsFiddle. In my current layout, all four divs have opacity: 1 and visibility: visible, while divs a and b both ...

AngularJS allows a function to return an array value, which can be displayed in separate blocks on

Building a program that involves working with an AngularJS array. I need to showcase the elements of the AngularJS array, returned by a function, in an organized manner. Each element should be displayed correspondingly - for example, 'first' cont ...

Get rid of the spaces in web scraping <tr> tags using Node.js

I've encountered a problem that goes beyond my current knowledge. I'm attempting to web-scrape a specific webpage, targeting the <tr> element in nodejs. Although I can successfully retrieve the content, it seems that the format is not as cl ...

"All my online spaces are chaotic and cluttered beyond belief, overflowing with content in high-definition

One issue that frequently arises for me when developing websites is related to media queries and resolution. I have utilized the following code using a max-width of 1920px: @media only screen and (max-width : 1920px) {} However, I am facing challenges in ...

Exploring Bootstrap navigation bars with customizable fixed content heights

I recently implemented Bootstrap navs into a dialog, but encountered an issue - every time I switch to another nav option, the dialog resizes due to the changing content height. To see the issue in action, you can visit this CodePen link: https://codepen. ...