Placeholder information is not displaying correctly on Bootstrap 5.2

I am currently working on a webpage using Bootstrap 5.2 and have the following code snippet included:

<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="91f3fefee5e2e5e3f0e1d1a4bfa3bfa1bcf3f4e5f0a0">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">

<div class="row mb-2">
  <div class="col-sm-12 form-floating">
    <input type="text" class="form-control d-flex" id="Company_Name" name="Company_Name" placeholder="ACME, Inc.">
    <label for="Company_Name">Company Name</label>
  </div>
</div>
<div class="row mb-2">
  <div class="col-sm-12 form-floating">
    <input type="text" class="form-control d-flex" id="Company_Website" name="Company_Website" placeholder="www.acme.com">
    <label for="Company_Website">Website</label>
  </div>
</div>
<div class="row mb-2">
  <div class="col-sm-12 form-floating">
    <input type="text" class="form-control d-flex" id="Contact_Person" name="Contact_Person" placeholder="Joe Smith">
    <label for="Contact_Person">Contact Person</label>
  </div>
</div>
<div class="row mb-2">
  <div class="col-sm-12 form-floating">
    <input type="text" class="form-control d-flex" id="Company_Email" name="Company_Email" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f65606a7c62667b674f6e6c626a216c6062">[email protected]</a>">
    <label for="Company_Email">Company Email</label>
  </div>
</div>
<div class="row mb-2">
  <div class="col-sm-4 form-floating">
    <input type="text" class="form-control d-flex" id="Company_Telephone" name="Company_Telephone" placeholder="999-999-9999" />
    <label for="Company_Telephone">Contact Telephone :</label>
  </div>
</div>

My aim is to have placeholder information displayed for each input field when there is no data present, but unfortunately, none of the placeholders are showing up when the form is displayed:

https://i.sstatic.net/wlEra.png

Upon inspecting the code source in Chrome, I notice that the placeholder information is present but not visible. Could it be related to the use of the form-floating class for field labels causing this issue? If not, does anyone have any insights on how to resolve this problem?

Answer №1

By utilizing some customized CSS, achieving this task becomes quite straightforward. I have integrated a <span> within the <label> element, which will vanish as soon as you input a value.

If you prefer the placeholder to vanish upon focusing, you can consult the CSS code provided -- feel free to uncomment the final section for this functionality.

.form-floating { overflow: hidden }
.form-floating label {
  align-items: center;
  display: flex;
  white-space: nowrap
}
.form-floating label>span {
  font-size: 0.875em;
  margin-left: 0.5em;
  opacity: 0.5;
  transition: opacity 250ms 0ms ease-in-out;
}

.form-floating>.form-control:not(:placeholder-shown)~label>span { opacity: 0 }


/* Uncomment the section below if you wish for the placeholder to vanish on focus */
/* .form-floating>.form-control:focus~label>span { opacity: 0 } */
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6d0f02021d0a0d0b18091d0e41201e021e001d520f0302">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">

<div class="row mb-2">
  <div class="col-sm-12">
    <div class="form-floating">
      <input type="text" class="form-control d-flex" id="Company_Name" name="Company_Name" placeholder="Company Name">
      <label for="Company_Name">Company Name <span>ACME, Inc.</span></label>
    </div>
  </div>
</div>
<div class="row mb-2">
  <div class="col-sm-12">
    <div class="form-floating">
      <input type="text" class="form-control d-flex" id="Company_Website" name="Company_Website" placeholder="Website">
      <label for="Company_Website">Website <span>www.acme.com</span></label>
    </div>
  </div>
</div>
<div class="row mb-2">
  <div class="col-sm-12">
    <div class="form-floating">
      <input type="text" class="form-control d-flex" id="Contact_Person" name="Contact_Person" placeholder="Contact Person">
      <label for="Contact_Person">Contact Person <span>Joe Smith</span></label>
    </div>
  </div>
</div>
<div class="row mb-2">
  <div class="col-sm-12">
    <div class="form-floating">
      <input type="text" class="form-control d-flex" id="Company_Email" name="Company_Email" placeholder="Company Email">
      <label for="Company_Email">Company Email <span><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="48222d27312f2b362a0223212f276c212d2f">[email protected]</a></span></label>
    </div>
  </div>
</div>
<div class="row mb-2">
  <div class="col-sm-4">
    <div class="form-floating">
      <input type="text" class="form-control d-flex" id="Company_Telephone" name="Company_Telephone" placeholder="Contact Telephone" />
      <label for="Company_Telephone">Contact Telephone <span>999-999-9999</span></label>
    </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 Google custom search bar to suit your preferences

I am looking to adjust the height of the Google custom search bar, and while there are various styling options available through the Google custom search editor, none specifically cater to changing the height. Currently, the search bar includes top and bo ...

Organize objects neatly in a grid formation

I have a .test div with grid-template-columns: auto auto auto;. The column width is set to vary based on the element width, and I also used justify-content: start; to align the columns to the left. I chose to use auto instead of 1fr to prevent the columns ...

Implement a responsive CSS division that simulates a two-column table

In my layout, I have three row divs: header, content, and footer. My goal is to create a table-like format within the content div to display information. Here's an example: .itemwrapper{width:600px;} .picture{width:150px;float:left;} .item{width:45 ...

The anticipated data originates from the 'style' attribute, which is formally noted within the 'IntrinsicAttributes & TextInputProps & RefAttributes<TextInput>' type

I have been working on developing a text form using typescript within the React Native framework. To accomplish this, I created a TextInput component specifically designed for email and password inputs. Below is the code I have been working with: TextInpu ...

Having trouble getting the CSS footer from cssstickyfooter.com to function properly

I tried implementing some basic CSS from to create a sticky footer that remains at the bottom of the page regardless of content length. However, I am encountering a problem with the footer not behaving as expected. There are actually two issues with the f ...

What's the best way to layer a fixed div over an absolutely positioned div?

I am in the process of developing a small web application. In this project, I have two div elements - one is set to absolute positioning and the other to static positioning. My goal is to position the static div on top of the absolute div, ensuring that it ...

What could be causing the discrepancy in sizes of the columns in my multi-column layout?

https://jsfiddle.net/drqjmssy/ Seeking assistance from the linked jsfiddle, I aim to align "div class='main_content'" vertically with "div class='sidebar'". What would be the best approach to achieve this alignment? In case the fiddle ...

Using FEWER loops to create column classes on Twitter - What is their functionality?

Bootstrap utilizes various LESS mixins to create its column classes, along with other classes; .make-grid-columns() { // Common styles for all sizes of grid columns, widths 1-12 .col(@index) when (@index = 1) { // initial @item: ~".col-xs-@{index} ...

How can I create a responsive input group with automatic width using Bootstrap 3.1?

I am having trouble with the layout of my two floating divs. The first div contains buttons and the second div contains an input-group. However, the input-group is moving down a line instead of utilizing the available space. Here is a link for reference: ...

Button with embedded Bootstrap dropdown

I need help with centering a dropdown menu on my webpage. I followed the instructions, but it's still appearing next to the button instead of in the center. Below is the code snippet: <div class="btn-group"> <button type=" ...

Enhancing the pagination look and feel in Laravel 5.1

Is it possible to customize the paginator layout in Laravel 5.1? I am looking to include first and last links along with the default previous and next links. I would like to change the previous and next links to show icons instead of text, while still ma ...

Comparing Strict CSS with Hacky CSS - Which is the Better Choice?

When working with CSS, it becomes evident fairly quickly that certain styles are not universally compatible across different browsers. For instance, achieving a semi-transparent PNG required a convoluted solution for Internet Explorer like: filter: pro ...

The nested navigation bar is not displaying properly below the main navigation bar

Hey there! I'm having a bit of trouble with adding a nested nav within my main nav. The issue is that the nested nav isn't aligning properly under the main nav. Take a look at this screenshot for reference. The nested nav seems to be shifted abou ...

When the CSS style sheet is not embedded within the HTML document, it fails

I'm facing an issue while trying to apply currency formatting to an HTML table in order to have it display correctly when opened in Excel. Initially, I tried doing this inline and it worked fine, like so: <td style="mso-number-format:$\##&bso ...

Failure in Bootstrap Typography #1 - Unable to locate proper class attribute values for uppercase and reverse transformations

<!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel= ...

changing size when hovered over with the mouse is not consistent between entering and exiting

Hi there, I'm currently utilizing the transform: scale(); property on a website and could use some assistance with a particular issue I haven't been able to find an answer for online. Here is the code snippet I'm working with: HTML: <d ...

Interactive Radial Menu Using Raphael JS

Greetings and thank you for taking the time to consider my predicament. I am currently working on creating an SVG menu using raphael, but unfortunately, geometry has never been my strong suit. Below is a visual representation of what I have managed to cre ...

The contents within the div element exceed the width of its parent element

Hey there, I'm currently working on a Rails application to showcase some links in a horizontal layout. The links are indeed displaying horizontally without wrapping, just as intended. However, I've noticed that the containing div is wider than th ...

Discover the complete compilation of CSS class regulations (derived from various stylesheets) along with their currently active properties for the chosen element

Is there a way to retrieve all the matched CSS Selectors for a selected element and access the properties of each active class applied to that element? I have researched methods like using getMatchedCSSRules and checking out However, I am hesitant to use ...

Is the width set to fill the entire partial screen?

I'm facing a dilemma: I want the darkest-gray bar at the bottom right (visible after running the code below) to stretch as far as the browser window allows without encroaching on the light-gray section on the left. Here's the code snippet: <d ...