【问题标题】:Blue border of the button after component opening组件打开后按钮蓝色边框
【发布时间】:2019-11-30 12:30:25
【问题描述】:

今天我在 HTML 组件中的关闭按钮遇到了一个奇怪的问题。即当我打开组件(客户的详细信息按钮)时,开头的关闭按钮被蓝色边框包围。单击组件上的任意位置后,边框消失。 如下图所示的问题:

我试图在我的 CSS 类中设置选项,如大纲:无,但它没有带来理想的结果。此外,当我将复制相同的组件时:

<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-label="Close"(click)="onClose()">
    <span aria-hidden="true">&times;</span>
  </button>
  <button type="button" class="close" aria-label="Close">
    <span aria-hidden="true">×</span>
  </button>
</div>

只有第一个关闭按钮有蓝色边框。

客户详细信息.coponent.html


<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal" aria-label="Close"(click)="onClose()">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

<h4 class="modal-title w-100 font-weight-bold">Customer details:</h4>

<div *ngIf="(this.customer$ | async) as customer; else loading">
  {{customer.name}}
</div>

<div *ngIf="(this.customer$ | async) as customer; else loading">
  {{customer.email}}
</div>

<div *ngIf="(this.customer$ | async) as customer; else loading">
  {{customer.phoneNumber}}
</div>


<ng-template #loading>
  Loading stuff in ngIf...
</ng-template>

我想要实现的只是在组件打开后不出现这个蓝色边框。我不确定这是否是我的浏览器的问题,但目前我正在使用谷歌浏览器。感谢您对我应该做些什么来达到理想效果的建议。

【问题讨论】:

  • 将css属性outline:none;设置为“关闭”按钮,应该可以解决您的问题。
  • 当您使用button html 标记时尤其会发生这种情况,如果您想在不覆盖默认按钮行为的情况下移除蓝色边框,请使用不同的标记,例如可点击的div跨度>
  • button:focus {outline:0;} 将解决此问题
  • 非常感谢您的快速回复。我的 CSS 声明有一个错误,这就是它无法正常工作的原因。再次感谢您提供即时提示。

标签: html css angular


【解决方案1】:

将 style="outline:none" 添加到您遇到问题的任何 div。

如果是按钮,你可以这样做

按钮:焦点 {outline:none;}

  <button type="button" style="outline:none" class="close" data-dismiss="modal" aria-label="Close"(click)="onClose()">
        <span aria-hidden="true">&times;</span>
   </button>

【讨论】:

    【解决方案2】:

    要解决这个问题,请使用下面的 css 来解决由于默认按钮焦点样式导致的蓝色边框线,请参考此链接 - What is the default style of the blue focus outline in Chrome?

    CSS 来解决这个问题:

    button:focus {
      outline: 0;
    }
    

    【讨论】:

      【解决方案3】:

      避免此类问题的一个好做法是重置 CSS:https://meyerweb.com/eric/tools/css/reset/

      html, body, div, span, applet, object, iframe,
      h1, h2, h3, h4, h5, h6, p, blockquote, pre,
      a, abbr, acronym, address, big, cite, code,
      del, dfn, em, img, ins, kbd, q, s, samp,
      small, strike, strong, sub, sup, tt, var,
      b, u, i, center,
      dl, dt, dd, ol, ul, li,
      fieldset, form, label, legend,
      table, caption, tbody, tfoot, thead, tr, th, td,
      article, aside, canvas, details, embed, 
      figure, figcaption, footer, header, hgroup, 
      menu, nav, output, ruby, section, summary,
      time, mark, audio, video {
          margin: 0;
          padding: 0;
          border: 0;
          font-size: 100%;
          font: inherit;
          vertical-align: baseline;
      }
      /* HTML5 display-role reset for older browsers */
      article, aside, details, figcaption, figure, 
      footer, header, hgroup, menu, nav, section {
          display: block;
      }
      body {
          line-height: 1;
      }
      ol, ul {
          list-style: none;
      }
      blockquote, q {
          quotes: none;
      }
      blockquote:before, blockquote:after,
      q:before, q:after {
          content: '';
          content: none;
      }
      table {
          border-collapse: collapse;
          border-spacing: 0;
      }
      

      【讨论】:

      • 感谢您的建议。据我所知,这个程序应该在项目的一开始就使用,以免弄乱:)
      • 没错!由于 css reset 解决了很多问题
      • 这些是我使用 HTML、Angular 等的第一步。学习好的实践还有很长的路要走。感谢您的承诺。
      • 勇气,这是一条漫长但伟大的道路;)medium.com/@vupham2909/…
      猜你喜欢
      • 2018-04-03
      • 1970-01-01
      • 2020-12-15
      • 1970-01-01
      • 2012-03-20
      • 2016-02-24
      • 2014-02-01
      • 1970-01-01
      • 2014-03-18
      相关资源
      最近更新 更多