Leveraging Font Awesome with Google's Autocomplete in Pac-Input

I'm experimenting with using the Font Awesome Map Marker in a Google Autocomplete Input. My aim is to position the Map Marker to the left of the placeholder text, apply color only to the map marker, and ensure that it remains visible even while the user is typing. I have attempted the following approach:

<span class="google-address-bar"><input #pacinput id="pac-input" class="form-control" type="text" placeholder="&#xf041;  Enter Your Street Address">
</span>

along with :

#pac-input {
    font-family: Fira-Sans, FontAwesome, Serif;
    background-color: #fff;
    width: 400px;
    height: 45px;
    font-size: 15px;
    font-weight: 300;
    text-overflow: ellipsis;
}

However, this solution does not allow me to add color specifically to the Map Maker, and when the input becomes dirty, the placeholder disappears. Has anyone found a way to achieve this?

Answer №1

To incorporate the Font Awesome element, utilize a <label> or <i> and then position the icon over the input. Simply adjust the padding to complete the effect.

html {
  box-sizing: border-box;
}
*,
*::before,
*::after {
  box-sizing: inherit;
  margin: 0;
  padding: 0;
}
.google-address-bar {
  position: relative;
}
.google-address-bar i.fa {
  color: red;
  position: absolute;
  height: 45px;
  line-height: 45px;
  padding-left: .5em;
}
#pac-input {
  font-family: Fira-Sans, Serif;
  background-color: #fff;
  width: 400px;
  height: 45px;
  font-size: 15px;
  font-weight: 300;
  padding-left: 1.5em;
  text-overflow: ellipsis;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet" />
<span class="google-address-bar"><i class="fa fa-map-marker"></i>
  <input #pacinput id="pac-input" class="form-control" type="text" placeholder=" Enter Your Street Address">
</span>

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

Having trouble getting CSS hover to work on hidden elements?

I am having trouble getting the rollover effect to work correctly on this page, and I can't seem to figure out what's causing the issue. My CSS is quite basic: open{visibility:hidden;} open:hover{visibility:visible;} If you would like to take ...

Tips for ensuring that hover:after contents do not impact the positioning of the next element

I have created a photo list section on my webpage. <div id="main_post_photo"> <% for(var q=0;q<resolve.length;q++){ if(resolve[q].images.length>=1){%> <a href='/post/<%= resolve[q]._ ...

Enhancing the mouse pointer in a JAVA application

Currently, I am immersed in a school project and trying to capture the attention of children by implementing a unique feature - a special mouse pointer. Imagine a pointer that moves, causing a small bird to follow its every movement. My project is based ...

Once it hits the fourth tab, it must not cycle back to the first one

Hi there, I'm new to JavaScript I noticed that when I click the left and right arrows, the tabs circle back to the beginning However, I would like the circle to stop. When it reaches the fourth tab, it should not go back to the first. This should also ...

smoothly hide the dropdown menu when a link is clicked with a transition effect

I am struggling with two bugs in my dropdown menu that I can't seem to fix. The navigation links on my homepage take users to different sections of the page instantly when clicked. However, the issue arises when the dropdown menu does not close after ...

Wordpress Sub-Menu Being Eclipsed by Banner

After upgrading my Wordpress to version 3.5.1, I noticed a problem on my site where the Submenus are loading but quickly getting hidden behind the Banner. Despite trying various modifications in the CSS file, the issue remains unresolved (and might have wo ...

Incorporating a scrollbar when a div exceeds the bottom of the viewport

I am encountering an issue on my webpage with a <div> that contains a <table> with rows of varying heights: <html> <head></head> <body> <div> <table> <tr>... <tr>... ... </ ...

Guide on triggering an open modal when clicking a link using jQuery

Creating a modal popup has always been my goal. After designing the CSS to style it, I found myself stuck as I lack knowledge in JQuery or JavaScript to code the functionality that animates and opens the modal upon clicking a button or link. Despite search ...

Combining blend-mode and filter in CSS: A comprehensive guide

Looking to achieve a specific image style by transforming a full color photo in the following ways: Convert it to greyscale Adjust the black levels (via decreased opacity or brightness) Apply a "multiply" blend mode with a blue color overlay So far, I&a ...

Tips on adjusting the width of a div container based on the size of an

I am struggling with setting the width of my "picBox" div equal to the image tag inside. I have tried adjusting the CSS code but cannot seem to get it right. Any suggestions on how to solve this issue would be greatly appreciated. Thank you. The CSS code: ...

Having issues with Tailwind classes not being applied properly on dynamically generated pages in Gatsby-node

Currently, I am working on building dynamic pages using gatsby-node. The templates for these pages are stored in the templates/ directory. However, I have run into an issue where I cannot utilize tailwind classes within these templates unless they are al ...

Is there a way to keep the background image stationary as I scroll?

As someone who is new to html and CSS, I recently tried to enhance my previous project by incorporating a background image that spans the entire screen size and remains fixed while scrolling up or down. Here is the code snippet: ''' body { ...

How to use JQuery to retrieve multiple background image URLs from CSS styling

Initially, here is the CSS code that I am working with: background-image: url(/style_elements/img/first.png), url(/style_elements/img/second.png); I am trying to specifically target the second background image URL using jQuery: var item_img_url = item_i ...

Making divs appear and disappear with the click of a checkbox

Exercise Table: <table class="table table-image" id="exercise_table"> <thead> <tr class="bg-hercules-font"> <th scope="col">Exercise Name</th> <th s ...

Tips for aligning text to the right and button to the left while ensuring responsive design with CSS

Trying to align text on the left and the button on the right with space between them in a responsive card design. The button has a background image added to it. Here is my attempted CSS, but the design is not yet fully responsive: .component { disp ...

Insert image using AJAX

I am attempting to use Ajax to dynamically add an <img> element to a div on my webpage. The image's name needs to be fetched from a database. Although I have successfully added the <img> tag to the div and set the correct source (src) att ...

Flexbox wrap allows you to determine which child element will move to the next line

Is there a way to control which child element in flexbox drops to the next line, instead of just the last one every time? For example: Full-size, no breaking: https://i.sstatic.net/proUB.png Default behavior, breaking the last element: https://i.sstatic.n ...

What is the proper way to execute a JavaScript function within a JavaScript file from an HTML file?

I have the following content in an HTML file: <!DOCTYPE html> <!-- --> <html> <head> <script src="java_script.js"></script> <link rel="stylesheet" type="text/css" href="carousel.css"> & ...

Creating an HTML table with collapsed borders and hidden rows/columns using the `border-collapse

I am facing a situation where I have a table with multiple lines as shown below: <table> <tr id="line1"><td>Line</td><td>1</td></tr> <tr id="line2"><td>Line</td><td>2</td></t ...

Making the most of Material Design icons in MaterializeCSS: A step-by-step guide

I am looking to customize my mdi icons by adding my own set of icons into custom classes. The existing mdi classes do not match my requirements. Is there a way for me to add these icons and use them just like the default ones? <i class="mdi-image-face ...