2016-03-29 13 views
1

写真のようにツールチップを作成したいと思います。タイトルタグの値はコントローラから来ています。 enter image description herejqueryなしでtitle属性を使用してカスタムツールチップを作成する方法

これは私のテーブルコードです:

<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> 

誰もがこのようなツールチップを提供するために、どのように私を助けることができます。

答えて

1

これは何か?

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>

+0

しかし、私は、私は、各セルは、更新された答えを参照ツールチップ –

+0

に示すべきである別の値を、持っているように、セルホバーでツールチップを表示するよう、TDタグでこれを使用したいです。 – NiZa

+0

私はあなたのコードを試しましたが、現在2つのツールチップを取得しています。 1つ前と1つ後また、タイトルに大きな文字列を追加すると、コンマから区切られません。私はツールチップの高さが増えていないことを意味します。水平方向に拡大しています –

0

あなたは:before:afterと協力し、いくつかの手動位置合わせを行うことができます。

ストロークとして:beforeを使用し、ツールチップに:afterを使用します。このようなものを作ることができます。

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/

+0

あなたのコードも試しました。どのようにホバー上に表示されるデフォルトのツールチップを非表示にするか、デフォルトの場所の代わりにホバー上にカスタムツールチップを表示することができますか?そして、どのようにしてカンマに基づいてツールチップの値を分けることができますか –

+0

デフォルトのツールチップを非表示/削除する: 'td'から' title'属性を削除する owsカンマに基づいてツールチップの値を区切ることはできますか?それを理解する。 – Pimmol

+0

タイトルの場合は、「Alaska、Arizona、California、Newzealand ...」のような値があります。ツールチップでは、1行に1つの名前しか表示しません。どうすればこれを実現できますか?投稿に添付された画像を参照して、私の質問をより明確に見ることができます –

関連する問題