1

I want to create a tooltip as shown in pic. Value in title tag is coming from controller. enter image description here

This is my table code:

<table border="1" cellpadding="10">
  <tbody style="white-space: nowrap;">
    <tr ng-repeat="row in rows">
      <td style="width: 2%;">
        <input type="checkbox" 
               ng-model="tableSelection[$index]"
               style="margin-left: 10px;">
      </td>
      <td style="font-size: smaller; width: 27%; color: gray; white-space: nowrap;"
          ng-repeat="col in input_columns"
          droppable="dropable"
          drop-fn="drop"
          drop-index="$index"
          drop-data="col"
          title=""
          ng-click="openDialog($event,$index)"
          tempValue="">&lt;enter data&gt;</td>

      <td style="font-size: smaller; width: 27%; color: gray; white-space: nowrap;"
          ng-repeat="col in output_columns"
          droppable="dropable"
          drop-fn="dropOutput"
          drop-index="$index"
          drop-data="col"
          title=""
          ng-click="openDialogOutputConst($event,$index)">&lt;enter data&gt;</td>
    </tr>
  </tbody>
</table>

Can anyone help me how to provide a tooltip like this.

2 Answers 2

1

Something like this?

td {
  position: relative;
}

td:hover:before {
  content: attr(data-title);
  position: absolute;
  background-color: yellow;
  top: 100%;
  width: 200px;
  white-space: normal;
  word-spacing: 200px; 
}
<table border="1" cellpadding="10">
  <tbody style="white-space: nowrap;">
    <tr ng-repeat="row in rows">
      <td style="width: 2%;">
        <input type="checkbox" ng-model="tableSelection[$index]" style="margin-left: 10px;">
      </td>
      <td style="font-size: smaller; width: 27%; color: gray; white-space: nowrap;" ng-repeat="col in input_columns" droppable="dropable" drop-fn="drop" drop-index="$index" drop-data="col" data-title="Idaho Illinois Indiana Iowa Kansas Missouri Nebraska Ohio"
      ng-click="openDialog($event,$index)" tempValue="">&lt;enter data&gt;</td>

      <td style="font-size: smaller; width: 27%; color: gray; white-space: nowrap;" ng-repeat="col in output_columns" droppable="dropable" drop-fn="dropOutput" drop-index="$index" drop-data="col" data-title="Some text here" ng-click="openDialogOutputConst($event,$index)">&lt;enter data&gt;</td>
    </tr>
  </tbody>
</table>

Sign up to request clarification or add additional context in comments.

5 Comments

But i want to use this with td tag as I want to show the tooltip on cell hover as each cell has different value, which should be shown on tooltip
I tried your code but getting two tooltips now. One before and one after. Also if i add a bigger string in title then it is not getting separated from comma. I mean tooltip height is not getting increased. It is expanding horizontally only
Check again. How do you mean two tooltips?
Like on hover getting one default grey colour tooltip and one yellow box before the td. Also how can I separate the tooltip on basis of comma as shown in the attached image
You should change title to data-title and give the tooltip a word-spacing with the same width value as his parent. See answer.
0

You could work with a :before :afterand do some manual positioning.

Using the :before as the stroke and the :after as the tooltip. You could create something like this.

body {
  margin-top: 100px;
}

.item {
  position: relative;

  display: inline-block;
  padding: 20px;

  background: #fff;
  border: 2px solid crimson;

  // the stroke
  // and the tooltip
  // hide them by default
  &:before,
  &:after {
    content: '';
    position: absolute;
    display: none;
  }

  // the stroke
  &:before {
    width: 100px;
    height: 2px;
    background: crimson;

    right: -100px;

    transform-origin: 0 0;
    transform: rotate(-20deg);
  }

  // the tooltip itself
  &:after {
    content: attr(title);
    color: #fff;

    top: -30px;
    right: -250px;

    width: 150px;
    padding: 5px;
    background: #000;
  }

  // when hover the item,
  // display before and after
  &:hover {
    &:before,
    &:after {
      display: inline-block;
    }
  }
}

https://jsfiddle.net/808443bt/

3 Comments

I tried your code too, can you help me how can I hide/remove the default tooltip which comes on hover and can only show the custom tooltip on hover in place of default one. And how can I separate the values in the tooltip based on comma
hide/remove the default tooltip: remove the title attribute from the td ow can I separate the values in the tooltip based on comma: I don't understand that one.
Like if in title I have values like "Alaska,Arizona,California,Newzealand...". In tooltip I want to show only one name per row. How can I achieve this. You can refer to the image attached in post for a more clear view of my query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.