【问题标题】:toolbar overlaps my button工具栏与我的按钮重叠
【发布时间】:2014-04-26 01:49:30
【问题描述】:

我正在将此应用程序移植到 node-webkit,并且我想制作自己的工具栏 + 关闭按钮。但是,我对css/html的了解并不多,我不知道如何做到这一点。

问题是我的工具栏与关闭按钮重叠,导致按钮无法使用。

CSS:

.toolbar{
    position: absolute;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 32px;
    -webkit-user-select: none;
    -webkit-app-region: drag;
    background: #776e65;
    cursor: pointer; }

button {
  -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
  -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
  box-shadow:inset 0px 1px 0px 0px #ffffff;
  background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
  background:-moz-linear-gradient( center top, #ededed 5%, #dfdfdf 100% );
  filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf');
  background-color:#ededed;
  -webkit-border-top-left-radius:6px;
  -moz-border-radius-topleft:6px;
  border-top-left-radius:6px;
  -webkit-border-top-right-radius:6px;
  -moz-border-radius-topright:6px;
  border-top-right-radius:6px;
  -webkit-border-bottom-right-radius:6px;
  -moz-border-radius-bottomright:6px;
  border-bottom-right-radius:6px;
  -webkit-border-bottom-left-radius:6px;
  -moz-border-radius-bottomleft:6px;
  border-bottom-left-radius:6px;
  text-indent:0;
  border:1px solid #dcdcdc;
  display:inline-block;
  color:#777777;
  font-family:arial;
  font-size:15px;
  font-weight:bold;
  font-style:normal;
  height:30px;
  width:30px;
  position: fixed;
    top: 0;
    right: 0;

HTML:

<div class="toolbar">

<button id="close">x</button>

JS:

onload = function() {

  var closeNode = document.getElementById('close');
  if (closeNode) {
    closeNode.onclick = function() {
      window.close();
    };
  }
}

UPD:代码现在可以在浏览器中运行,但不能在 node-webkit 内部使用 -webkit-app-region: no-drag;

【问题讨论】:

    标签: javascript html css node-webkit


    【解决方案1】:

    您可以将&lt;button&gt; 移动到工具栏内部或之前,以强制按钮具有更高的 z-index。

    另一种方法是给 .toolbarbutton css 定义你已经明确的z-index 属性,并使按钮具有更高的索引。

    .toolbar {
      z-index: 10000;
    }
    
    button {
      z-index: 10001;
    }
    

    注意:button 的样式将应用于页面上的所有按钮,因此您最好为该按钮专门编写一个新类或包含像 .some-outer-element button 这样的选择器。

    【讨论】:

      【解决方案2】:

      您可以使用 z-index 将按钮定位在工具栏的顶部。

      .toolbar {
          z-index:1;
      }
      
      button {
          z-index:2;
      }
      

      DEMO

      根据父元素中是否有其他元素,您可能需要使用 z-index 值来让它们以您想要的方式显示。只需确保按钮的 z-index 大于工具栏的 z-index。

      【讨论】:

      • 那种工作,它在工具栏右下角创建了一个不可见的区域,改变光标,如果点击关闭应用程序。按钮本身是不可见的,并且没有按预期定位在 Node-Webkit 中顺便说一句这是整个应用程序的 .nw 文件,以防mega.co.nz/…
      • @Konata 您可以尝试为按钮设置更高的 z-index。它在 jsfiddle 中工作,因此您的应用中可能还有其他东西在调整它。
      • 当我在浏览器中打开应用程序时它可以工作,但是当使用 node-webkit 实例时它只是不存在:(
      • @konata 抱歉,我对 node-webkit 不够熟悉,无法帮助您。
      【解决方案3】:

      使用它并检查..

      .toolbar{
                width: 100%;
              height: 32px;
              -webkit-user-select: none;
              -webkit-app-region: drag;
              background: #776e65;
              cursor: pointer; 
      }
      
          button {
              float:right;
            -moz-box-shadow:inset 0px 1px 0px 0px #ffffff;
            -webkit-box-shadow:inset 0px 1px 0px 0px #ffffff;
            box-shadow:inset 0px 1px 0px 0px #ffffff;
            background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf) );
            background:-moz-linear-gradient( center top, #ededed 5%, #dfdfdf 100% );
            filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf');
            background-color:#ededed;
            -webkit-border-top-left-radius:6px;
            -moz-border-radius-topleft:6px;
            border-top-left-radius:6px;
            -webkit-border-top-right-radius:6px;
            -moz-border-radius-topright:6px;
            border-top-right-radius:6px;
            -webkit-border-bottom-right-radius:6px;
            -moz-border-radius-bottomright:6px;
            border-bottom-right-radius:6px;
            -webkit-border-bottom-left-radius:6px;
            -moz-border-radius-bottomleft:6px;
            border-bottom-left-radius:6px;
            border:1px solid #dcdcdc;
            display:inline-block;
            color:#777777;
            font-family:arial;
            font-size:15px;
            font-weight:bold;
            font-style:normal;
            height:30px;
            width:30px;
      }
      

      【讨论】:

      • 上面的代码把工具栏的间距打破了~70px,并添加了一个滚动条,仍然没有按钮
      猜你喜欢
      • 2011-02-20
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 2017-02-21
      • 1970-01-01
      • 1970-01-01
      • 2016-04-29
      相关资源
      最近更新 更多