Showing a tooltip on the right side of a control with an arrow pointing towards it in a colored

Can someone help me with displaying a tooltip to the right end of a control, with the arrow facing the same direction and changing the background color of the arrow to red?

Here is my attempt so far

<input id="age" title="test tooltip">
 $( document ).tooltip({
      position: {
        my: "right bottom-20",
        at: "center top",
        using: function( position, feedback ) {
          $( this ).css( position );
          $( "<div>" )
            .addClass( "arrow" )
            .addClass( feedback.vertical )
            .addClass( feedback.horizontal )
            .appendTo( this );
        }
      }
    });
 .ui-tooltip, .arrow:after {
    background: black;
     }
  .ui-tooltip {
    padding: 10px 20px;
    color: white;    
    font: bold 14px "Helvetica Neue", Sans-Serif;

  }
  .arrow {
    width: 70px;
    height: 16px;
    overflow: hidden;
    position: absolute;
    left: 50%;
    margin-left: -35px;
    bottom: -16px;
  }
  .arrow.top {
    top: -16px;
    bottom: auto;
  }
  .arrow.left {
    left: 20%;
  }
  .arrow:after {
    content: "";
    position: absolute;
    left: 20px;
    top: -20px;
    width: 25px;
    height: 25px;

    -webkit-transform: rotate(45deg);
    -moz-transform: rotate(45deg);
    -ms-transform: rotate(45deg);
    -o-transform: rotate(45deg);
    tranform: rotate(45deg);
  }
  .arrow.top:after {
    bottom: -20px;
    top: auto;
  }

Answer №1

Modification

If you want to achieve this look:

Start by removing the .arrow class and adding the following to your CSS :

.ui-tooltip-content::after {
    top: calc(50% - 10px); /* Formula for half height minus 10px */
    left: -10px;
    border-color: transparent red;
    border-width: 10px 10px 10px 0;
    content: '';
    position: absolute;
    border-style: solid;
    display: block;
    width: 0;
}

To align your tooltip to the right, use this in your JavaScript:

position: {          
   my: 'right center', 
   at: 'left-10 center'
   ...
}

Test it out with a demo here.

About calc() : A method for computing values for length units, like width: calc(100% - 3em)

This feature is supported in major desktop browsers.


Original response (will be removed upon approval)

I believe this is the desired outcome you're looking for:

Update your JavaScript positioning to:

position: {
    my: "left bottom-20",
    at: "center top",
    ...

For the red arrow effect, include this snippet in your CSS:

.arrow:after{
    background:red;
}

Answer №2

.pointer:after {
  content: "";
  height: 55px;
  left: 72px;
  position: absolute;
  transform: rotate(75deg);
  width: 91px;
}
.pointer.top {
  bottom: -3px;
}
.pointer.left {
  left: -18%;
}

Answer №3

It can be a bit challenging to position the tooltip with Jquery UI as it handles a lot of background work for this purpose.

You can see my example here: http://jsfiddle.net/pa5N8/1/

I have customized the .arrow.left class to show a left-facing arrow using CSS borders, positioning it precisely in the center of the input field's wall.

This method works well if your input fields have consistent dimensions. If not, I suggest considering another library like tipsy:

Best of luck!

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

Tips for aligning two columns of listed items vertically with Bootstrap 5 or CSS

Having difficulty aligning two columns containing text - specifically, two lists. The goal is to have both columns on the same row with centered lists and their respective items aligned as normal bullet points. Any advice would be greatly appreciated. C ...

When using NextJS, the dynamically generated HTML elements do not get affected by CSS repaint

Recently, I encountered an issue while working on a Next.js project involving the addition of an external script that uses vanilla JavaScript to dynamically create nodes. Despite importing global CSS at the top of my _app.js file, I noticed that the styles ...

What is the best way to position an image in the bottom right corner of a fluid div container?

I am struggling to position this icon image at the bottom right hand corner of this div, so that it appears as if the message is originating from the icon's head. Despite my efforts, I have yet to find a definitive solution. https://i.stack.imgur.com ...

The autofill ajax script is unable to populate dynamically added rows

As a newcomer to programming, I am trying to create a table that allows users to add new rows by clicking a button. Each row should have a field for inputting an ID which corresponds to some predefined numbers in another table, and then the other field sho ...

Identifying a change in the source location of an iframe element

I am working with an iframe object that is currently set to a specific page's URL. Here is an example: <iframe src="http://en.wikipedia.org/wiki/Special:Random"></iframe> My goal is to display an alert whenever the location of the iframe ...

Angular 14: Exploring the left datepicker panel navigation in PrimeNG

In my situation, I am trying to adjust the position of the date-picker in relation to a panel displayed within a <p-calendar> element. Due to a splitter on the right side, I need to shift the date-picker towards the left. Here is the HTML code: < ...

Adjusting webpage zoom based on different screen sizes

Hey there, I ran into an issue with my web page design. It looks great on my desktop monitors, but when I checked it on my laptop, things went haywire. Strangely, adjusting the zoom to 67% seemed to fix the problem. Both screens have a resolution of 1920 ...

The ajax Success function fails to work when set to receive JSON data

My task involves adding an attendance record for a group of students within a classroom using a Bootstrap modal. Below is the code snippet for my Bootstrap modal, containing a form: <div id = "add_attendance_modal" class = "modal fade&qu ...

Tips for reducing the height of the footer without compromising the alignment of the text within

My attempt to reduce the height of my footer in CSS using padding, margin, and other methods was unsuccessful. All of these adjustments either pushed the footer completely out of the bottom or left the text uncentered. footer { background: #fce138; wid ...

capture the alteration of text within an input field

Currently, I am utilizing the Joomla calendar feature to select a date. The HTML code for this functionality is displayed below. When you click on the image, a calendar will pop up allowing you to choose a date. Once selected, the popup closes and the date ...

Ways to conceal Bootstrap-designed elements behind a fullscreen overlay

I'm attempting to create a transparent layer to conceal the entire content of my page behind it. It works fine without the Bootstrap columns, but as soon as I add the columns for responsive design, it stops working (or maybe I'm just not understa ...

What is the best way to construct the following layout with columns in Bootstrap?

My approach involved dividing the content into two equal columns using col-md-6. Each of these was further split into 3 columns using col-md-4. However, I faced an issue regarding achieving consistent spacing between columns on the right side. https://i.s ...

What is the method for creating a border around text like the Google login feature?

Did Google update the login TextBox to look like this today? https://i.sstatic.net/bXPQu.png There is a border around the text, what is the most effective method to achieve this using HTML & CSS? Update: A single answer can be found on StackOverflow ...

Can a line be created using only CSS without the need for an additional HTML element?

There have been many inquiries regarding drawing lines without adding an additional HTML element. Consider this scenario with an HTML div element: <div class="myDiv"></div> Accompanied by the following CSS: .myDiv{ width: 100px; height: ...

Why doesn't setting the SVG viewBox to "0 0 100 100" scale my path to 100%?

My current dilemma involves an SVG path that is only displaying at 50% of its intended size. How can I adjust it to show at 100%? Below is the code snippet in question: <div className="svgPathContainer"> <svg width="100%" he ...

Trouble with Scroll Snap and Navbar Toggle Malfunctioning on Browser Resize

I've run into a problem with scroll snap on my website. Every time the screen size changes, like when the mobile browser's navbar is opened or closed, the scroll snap behavior goes haywire. Even after returning to the top of the page, the snap fe ...

Prevent PHP from escaping JSON string when saving to a file

I am facing an issue while trying to save changes to a JSON file using JQuery and PHP. It seems that my PHP script is escaping characters when saving out the JSON, making it unreadable. The following code snippet passes the JSON object ('family' ...

If a checkbox is checked, then the value in the textbox should be multiplied by 0

I'm faced with a challenge involving a non-clickable textbox that is meant to hold a running total. Each time a checkbox is clicked, its value should be added to the total in the textbox. However, I am now struggling to figure out how to perform mult ...

In JavaScript, the task involves filtering through multiple arrays of objects to calculate the average value based on the contract number

Every object in the Array contains a contractNumber, but with repeated values. I am attempting to determine the average value of each unique contractNumber. var vendorArr=[{ "contractNumber":5258, "monthId":0, "value":2}, { ...

How can I use HTML code to style the header cell values of a table?

Can someone please assist me with creating a table header style that looks like the one in the image? Additionally, how can I turn the name and picture area into a block and add borders to them? I'm also having trouble with my list icons showing up a ...