nar*_*nob 5 javascript css twitter-bootstrap angularjs angular-ui-bootstrap
我在这里有一个关于我的问题的工作示例:http : //plnkr.co/edit/vwZS5e?p=preview
这是问题范围:
<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>
Run Code Online (Sandbox Code Playgroud)
当我将鼠标悬停在它上面时,我试图在此跨度的中心上方显示一个弹出框。当文本太长时,我使用文本溢出来切断我的文本。但似乎 uib-popover 并没有考虑到溢出.. popover 出现在右边太远了。
这是我的CSS:
.test-container {
text-overflow:ellipsis;
overflow:hidden;
width:100px;
border:1px solid red;
margin-top:50px;
margin-left:50px;
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以将弹出框放在测试容器 div 上,但我更希望弹出框位于跨度的中心。
有没有人知道如何解决这个问题?
<span>是一个inline元素,元素width的inline性质取决于它的内容。如果您添加更多内容,其宽度将会增加,反之亦然。
在上述情况下,即使没有空格,您也有很长的文本字符串。如果你检查你的,<span>你会发现widthof比它的父级<span>大得多。width.test-container
uib-popover正在根据 采取其width立场<span>。如果您增加或减少<span>元素的内容,您也会看到其位置的变化uib-popover。
您可以通过创建<span>一个block元素并在其上移动文本剪辑属性来解决此问题。
(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;
}
})();Run Code Online (Sandbox Code Playgroud)
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;
}Run Code Online (Sandbox Code Playgroud)
<link data-require="bootstrap@*" data-semver="3.3.5" rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<script data-require="jquery@*" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script data-require="bootstrap@*" data-semver="3.3.5" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script data-require="angular.js@1.4.6" data-semver="1.4.6" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-animate.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/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>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5642 次 |
| 最近记录: |