javascript - Angular uib-popover displays in wrong position when set on overflowed text - Stack Overflow

I have a working example of my issue here:Here's the problem span:<div class="test-contain

I have a working example of my issue here:

Here's the problem span:

<div class="test-container">
    <span uib-popover="Test"
          popover-placement="top"
          popover-trigger="mouseenter"
          popover-append-to-body="true">
        MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe
    </span>
</div>

I'm trying to display a popover above the center of this span when I mouseover it. I'm using text-overflow to cut off my text when it's too long. But it seems like uib-popover doesn't account for the overflow.. the popover appears way too far to the right.

Here's my css:

.test-container {
    text-overflow:ellipsis; 
    overflow:hidden; 
    width:100px; 
    border:1px solid red; 
    margin-top:50px; 
    margin-left:50px;
}

I know I can place the popover on the test-container div, but I'd prefer the popover be in the center of the span.

Does anyone have an idea on how to fix this?

I have a working example of my issue here: http://plnkr.co/edit/vwZS5e?p=preview

Here's the problem span:

<div class="test-container">
    <span uib-popover="Test"
          popover-placement="top"
          popover-trigger="mouseenter"
          popover-append-to-body="true">
        MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe
    </span>
</div>

I'm trying to display a popover above the center of this span when I mouseover it. I'm using text-overflow to cut off my text when it's too long. But it seems like uib-popover doesn't account for the overflow.. the popover appears way too far to the right.

Here's my css:

.test-container {
    text-overflow:ellipsis; 
    overflow:hidden; 
    width:100px; 
    border:1px solid red; 
    margin-top:50px; 
    margin-left:50px;
}

I know I can place the popover on the test-container div, but I'd prefer the popover be in the center of the span.

Does anyone have an idea on how to fix this?

Share Improve this question asked Dec 14, 2015 at 23:04 nardnobnardnob 1,05614 silver badges28 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

<span> is an inline element and width of an inline element depends on its content. If you will add more content, its width will increase and vice versa.

In above situation, you have very long string of text even without spaces. If you will inspect your <span> you will see that the width of <span> is much larger than the width of its parent .test-container.

uib-popover is taking its position according to the width of <span>. If you will increase or decrease content of <span> element you will see change in position of uib-popover as well.

You can fix this by making <span> a block element and moving text clipping properties on it.

(function(){
  'use strict';

  angular
    .module('app', ['ui.bootstrap', 'ngAnimate']);
})();

(function(){
  'use strict';

  angular
    .module('app')
    .controller('appController', AppController);

  AppController.$inject = ['$log', '$timeout'];

  function AppController($log, $timeout) {
    var vm = this;

    return vm;
  }
})();
html,
body {
  background-color:darkgray;
}

.test-container {
  width:100px; 
  border:1px solid red; 
  margin-top:50px; 
  margin-left:50px;
}

.test-container span {
  text-overflow:ellipsis; 
  overflow:hidden;
  display: block;
}
<link data-require="bootstrap@*" data-semver="3.3.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn./bootstrap/3.3.5/css/bootstrap.min.css" />
  <script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery./jquery-2.1.4.min.js"></script>
  <script data-require="bootstrap@*" data-semver="3.3.5" src="https://maxcdn.bootstrapcdn./bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script data-require="[email protected]" data-semver="1.4.6" src="https://cdnjs.cloudflare./ajax/libs/angular.js/1.4.6/angular.min.js"></script>
  <script src="//ajax.googleapis./ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
  <script type="text/javascript" src="//cdnjs.cloudflare./ajax/libs/angular-ui-bootstrap/0.14.3/ui-bootstrap-tpls.min.js"></script>

<div ng-app="app" data-ng-controller="appController as vm">
  <div class="test-container">
    <span uib-popover="Test"
          popover-placement="top"
          popover-trigger="mouseenter"
          popover-append-to-body="true">
      MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe..MouseoverMe
    </span>
  </div>
</div>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745438070a4627701.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信