Concern regarding the appearance of tooltip positions

Incorporated Bootstrap to enhance the design....The popover tooltip positioning is not behaving as expected. I want it to display in the far right corner with the Glyphicon, but it keeps appearing on the left.

What I attempted previously:

1) I modified the CSS to try and align the popover to the right, yet it didn't yield the desired results.

$("[data-toggle=popover]").popover({
    html: "true", 
container: 'body',
 title : 'Contact Us <a href="#" class="close" data-dismiss="alert">&times;</a>',
content: function() {
          return $('#popover-content').html();
        }
});
 $(document).on("click", ".popover .close" , function(){
        $(this).parents(".popover").popover('hide');
    });
.form-control {width:120px;}
.popover {
max-width:300px;}
#contact_query.btn.btn-primary
{
background-color:#74a5d0;

}
#call_icon.glyphicon.glyphicon-earphone {

    position: fixed;
top: 8px;
right: 16px;
font-size: 30px;

}


@media (max-width: 767px) {
   #contact_query.btn.btn-primary
{
font-size:13px;


}

#query-pos
{
font-size:13px;

}
#email-pos
{
font-size:13px;

}
#ph_1,#ph_2
{
font-size:13px;
}

}
<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<body>
<div class="container">
  <ul class="list-unstyled">
    <li><a data-placement="right" data-toggle="popover" data-title="" data-container="body" type="button" data-html="true" href="#contact" id="login_try"><span id="call_icon" class="glyphicon glyphicon-earphone"></span></a></li>
   
<div id="popover-content" class="hide">

      <form class="form-inline" role="form">
        <div class="form-group"> 
         <div class="row">
    <div class="col-xs-12" ><div>123123121231 &nbsp;&nbsp;<a id="ph_1" href="tel:+9112313313123" type="submit" class="btn btn-primary" ><span class="glyphicon glyphicon-earphone"></span></a></div><br/></div>
    <div class="col-xs-12" ><div>1231231223 &nbsp;&nbsp;<a id="ph_2" href="tel:+91121312312" type="submit" class="btn btn-primary" ><span class="glyphicon glyphicon-earphone"></span></a></div></div>
          </div><hr>
  <div class="row">
  <div class="col-xs-12"><p><b>Unable to Contact us? </b><br/>
  <p id="query-pos"><a id="contact_query" href="#"  class="btn btn-primary">Send your Query</a> and our team will get back to you at the earliest.</p></p></div></div>
  <div ><hr><p><b>Or you can</b><br/><p id="email-pos">E-mail us @ <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89ecf1e8e4f9e5ecc9ecf1e8e4f9e5eca7eae6e4">[email protected]</a>?Subject=Help%20Client"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bdd8c5dcd0cdd1d8fdd8c5dcd0cdd1d893ded2d0">[emailprotected]</a></a></p></p></div>
  
        </div>
      </form>
 
    </div>
  </ul>
</div>
</body>
</html>

Answer №1

To ensure proper alignment of the popover relative to the anchor that triggers it, add the CSS property position: fixed to the anchor itself rather than to the icon element.

.phone_icon {
  position: fixed;
  top: 8px;
  right: 16px;
}

#call_icon.glyphicon.glyphicon-earphone {
  font-size: 30px;
}

Additionally, adjust the data-placement attribute to "left" if there is no available space on the right side for the popover.

$("[data-toggle=popover]").popover({
  html: "true",
  container: 'body',
  title: 'Contact Us <a href="#" class="close" data-dismiss="alert">&times;</a>',
  content: function() {
    return $('#popover-content').html();
  }
});
$(document).on("click", ".popover .close", function() {
  $(this).parents(".popover").popover('hide');
});
.form-control {
  width: 120px;
}

.popover {
  max-width: 300px;
}

#contact_query.btn.btn-primary {
  background-color: #74a5d0;
}

.phone_icon {
  position: fixed;
  top: 8px;
  right: 16px;
}

#call_icon.glyphicon.glyphicon-earphone {
  font-size: 30px;
}

@media (max-width: 767px) {
  #contact_query.btn.btn-primary {
    font-size: 13px;
  }
  #query-pos {
    font-size: 13px;
  }
  #email-pos {
    font-size: 13px;
  }
  #ph_1,
  #ph_2 {
    font-size: 13px;
  }
}
<!DOCTYPE html>
<html>

<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

  <body>
    <div class="container">
      <ul class="list-unstyled">
        <li><a class="phone_icon" data-placement="left" data-toggle="popover" data-title="" data-container="body" type="button" data-html="true" href="#contact" id="login_try"><span id="call_icon" class="glyphicon glyphicon-earphone"></span></a></li>

        <div id="popover-content" class="hide">

          <form class="form-inline" role="form">
            <div class="form-group">
              <div class="row">
                <div class="col-xs-12">
                  <div>123123121231 &nbsp;&nbsp;<a id="ph_1" href="tel:+9112313313123" type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-earphone"></span></a></div><br/></div>
                <div class="col-xs-12">
                  <div>1231231223 &nbsp;&nbsp;<a id="ph_2" href="tel:+91121312312" type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-earphone"></span></a></div>
                </div>
              </div>
              <hr>
              <div class="row">
                <div class="col-xs-12">
                  <p><b>Unable to Contact us? </b><br/>
                    <p id="query-pos"><a id="contact_query" href="#" class="btn btn-primary">Send your Query</a> and our team will get back to you at the earliest.</p>
                  </p>
                </div>
              </div>
              <div>
                <hr>
                <p><b>Or you can</b><br/>
                  <p id="email-pos">E-mail us @ <a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc99849d918c9099bc99849d918c9099d29f9391">[email protected]</a>?Subject=Help%20Client"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b7e637a766b777e5b7e637a766b777e35787476">[email protected]</a></a></p>
                </p>
              </div>

            </div>
          </form>

        </div>
      </ul>
    </div>
  </body>

</html>

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

Implementing a feature to close the drawer component from the main page by clicking on the menu button in React-js

Just starting out with reactjs and I've got my main page set up like this: <div > <AppBar position="flex" style={{backgroundColor:'#1A437E'}}> <Toolbar> <IconButton edge="end" color= ...

How can I maintain text alignment when it wraps around a floated element?

Currently, I am working on a responsive website project. In the example code provided, I have set the width of the container div to a fixed value to highlight a specific issue. The problem arises when the text wraps onto multiple lines and extends beyond ...

Best practices for server side countdown implementation

Issue I am facing a challenge with displaying a server-side countdown on the client side. Initially, I set it up using socket.io to emit data every 100 milliseconds. While I like this approach, I am concerned about potential performance issues. On the o ...

There may be instances where data is null in Java Spring and React JS

My goal is to store all data using react.js and Java Spring. I have sent data via REST, but one of the data classes is coming up as null in the MongoDB collections. I have checked to ensure that all data types are the same but I am unable to identify and r ...

"The NextJS FetchError that occurred was due to a timeout issue (ET

After successfully deploying my project on CentOS 7, I set up port forwarding to access it through port 8080. This means that in order to use the site, you had to navigate to it using the IP followed by :8080. Below is the NGINX configuration I utilized fo ...

Tips for optimizing the video loading and playback speed in a Next.js/React application

I have a page on my Next.js website: The video on the page seems to load slowly. This is how the video element is implemented: <video width="100%" autoPlay muted loop playsInline style={{ position: "absolute", l ...

Can a function be improved by including a sourceLocation property?

Building upon the discussion in this thread, I have a related query. When examining the properties of a function, we can see it has a name and a length among other things. Is there a way to add a new property to all functions by manipulating the construct ...

Creating a many-to-many relationship in Sequelize using a join table to insert data

I recently set up two models in sequelize with a many-to-many relationship. While Sequelize successfully created the join table, I am facing difficulties when trying to insert data into it. Despite going through the documentation section on associations ...

Expand and collapse navigation menu using Jquery

I am currently working on a navigation list that should open and close when clicked. However, I am facing an issue where using nav ul li.test a to open the hidden ul on click is not working as expected. When I try using nav ul li.test without a, the hidd ...

The malfunctioning of my Ajax functionality is causing issues

Today, I delved into the world of Ajax. I took the time to practice and follow step-by-step instructions on how to use AJAX, but unfortunately, I encountered an issue. I couldn't pinpoint the problem as there were no warnings displayed in the console. ...

A simple method to obtain the ID of the element that has been clicked and save it in a variable to be utilized in a function responsible for

Seeking assistance in optimizing the code below by removing the specific #static id and allowing for dynamic IDs such as #dynamic within the one click function. This would eliminate the need to repeatedly copy and paste the same function with different ID ...

In the realm of HTML Canvas, polygons intricately intertwine with one another

Currently, I am attempting to create multiple polygons from a large JSON file. Instead of being separate, the polygons seem to be connected in some way. https://i.sstatic.net/Ce216.png The project is being developed in next.js. Below are the relevant co ...

We regret to inform you that an error has occurred: "Uncaught ReferenceError: data is not defined at (index

I'm currently working in node.js and my main objective is to transfer an object from the server js side to the client js side. I attempted the following: on the server-side route router.get("/", function(req, res){ var data = {name : "gohar" , ...

Module output is "Undefined" when it is required

testing.js var something = require('./something'); var anotherThing = require('./anotherThing'); console.log(something()); console.log(anotherThing()); something.js module.exports = function() { console.log('Inside of someth ...

Every time I attempt to submit the login form on the Ionic and Angular page, instead of capturing the values of the form group, the page simply refreshes

Struggling with submitting the login form in Ionic and Angular? When attempting to submit, the page reloads instead of capturing the form group values. I am utilizing angular reactive forms and form builder within the ionic framework. Need assistance in id ...

Implementing validation in ASP.Net along with JavaScript for both the update and cancel buttons

My main objective is to show a message during the server roundtrip of an ASP.Net WebForm. Within my WebForm, there are two buttons: an update button and a cancel button. The message should always appear if either the update button or the cancel button is c ...

Find out the count of div elements using jQuery

I am utilizing jQuery Tools () for creating tooltips. In my js file, I have included the following code snippets: $("div#example-0").tooltip('#example-0-tooltip'); $("div#example-1").tooltip('#example-1-tooltip'); $("div#example-2").to ...

Javascript Google Maps API is not working properly when trying to load the Gmap via a Json

Trying to display a map using Gmaps and Jquery Ajax through JSON, but encountering difficulty in getting the map to appear on the page. The correct coordinates are being retrieved as confirmed by testing in the console. Puzzled by why it's not showin ...

What is the best way to remove the space between the footer and the bottom of the page

Is there a way to close this distance? I am referring to the gap between the element with text "Jakaś sobie stopka" and the end of the page. Visit this link for more details ...

What measures can I take to hide the browser's rendering of an image?

I've noticed that when I insert new images into the DOM, occasionally I can observe the image being displayed in a top to bottom manner. Is there a simple JavaScript method or event handler that I could utilize to ensure that the entire image only app ...