Bootstrap UI:如何更改弹出窗口的背景颜色

6
我正在尝试通过创建自定义的弹出框类来更改Bootstrap UI 弹出框的背景颜色(例如使用popover1popover2等而不是popover)。我知道这适用于普通的Bootstrap弹出框(这是示例链接:fiddle),但是似乎无法适用于Bootstrap UI弹出框。
当我将相同的方法应用于Bootstrap UI弹出框时,它只显示一个微小的空白弹出框。到目前为止,我已经做的就是更改了:
<a class="btn btn-primary popover-container" id="popover" data-toggle="popover" data-placement="right" data-container="body" rel="log-popover">Log level</a>

to

<a class="btn btn-primary popover-container" popover-placement="right" popover-template="'partials/loglevel-template.html'" popover-trigger="click">Log level</a>

loglevel-template.html

<div class="popover1">
    <div class="arrow"></div>
    <div class="popover-content">
       <p>some content</p>
    </div>
</div>

当我删除popover1类时,它可以正常工作,所以只需让弹出框显示就没有功能问题。
我更喜欢使用Bootstrap UI的弹出框,因为您不必在jQuery中使用任何硬编码模板(事实上,您根本不需要编写任何jQuery)。 我只是无法弄清楚如何更改Bootstrap UI弹出框的背景颜色。 在我深入研究之前,我想知道是否有其他人已经实现了这一点,或者是否有一个简单的解决方法(也许Bootstrap UI弹出框使用与普通弹出框不同的一组类)。 如果只是覆盖一些CSS类,那将是理想的解决方案。

你使用任何预处理器还是只用原始的CSS? - Raptus
1个回答

3

很不幸,这个解决方案在UI Bootstrap文档中没有得到记录,我也很不幸花了几个小时才找到这个极其简单的解决方案,但希望这可以为其他人节省一些时间。您可以在放置指令的元素上添加popover-class属性,然后相应地设置弹出窗口样式。有关详细信息,请参见下面的代码片段:

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('PopoverDemoCtrl', function ($scope, $sce) {
  
  $scope.dynamicPopover = {
    content: 'Hello, World!',
    templateUrl: 'myPopoverTemplate.html',
    title: 'Title'
  };

});
.trigger-popover-button {
  margin: 25% 0 0 10%;
}

.custom-dynamic-popover-class {
  color: red;
}

.custom-dynamic-popover-class > .popover-inner > .popover-title {
  background: yellow;
}

.custom-dynamic-popover-class > .popover-inner > .popover-content {
  background: blue;
}
<!doctype html>
<html ng-app="ui.bootstrap.demo">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.3.3.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

    <div ng-controller="PopoverDemoCtrl">
    
      <button uib-popover-template="dynamicPopover.templateUrl" 
              popover-title="{{dynamicPopover.title}}" 
              popover-class="custom-dynamic-popover-class"
              type="button" 
              class="btn btn-default trigger-popover-button">
        Popover With Template
      </button>

      <script type="text/ng-template" id="myPopoverTemplate.html">
        <div>{{dynamicPopover.content}}</div>
        <div class="form-group">
          <label>Popup Title:</label>
          <input type="text" 
                 ng-model="dynamicPopover.title" 
                 class="form-control">
        </div>
      </script>
   
    </div>
  </body>
</html>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接