【问题标题】:How to make z-index to work?如何使 z-index 工作?
【发布时间】:2016-04-19 08:11:27
【问题描述】:

我正在编辑一个 Angular 项目,我正在尝试修复以下功能:

我会得到以下行为:

这是 HTML 代码:

    <div class="search-function" ng-click="showInputForm()">
      <img src="../images/my_project/search.png">
    </div>

    <div class="search-form" ng-if="showForm">
      <form ng-submit="textSearch()">
        <input type="text" autofocus class="search-input" ng-model="text.value" />
      </form>
    </div>

正如您所见,当用户单击搜索图标时会出现白框,但它应该出现在图标上,而不是在图标下方。如何将其与搜索图标重叠?

这是 LESS 代码:

.search-function {
  margin-left: 30%;
}

.search-form {
  padding-left: 15%;
  padding-right: 15%;

  .search-input {
    color: #2b84a6 !important;
    background-color: #fff !important;
    font-weight: 300;
    font-size: 16px;
  }
}

我尝试将z-index: -1 设置为search-function 类,但它不起作用。 怎么了?

【问题讨论】:

    标签: html angularjs less z-index overlap


    【解决方案1】:

    z-index 仅适用于 定位 元素。由于您尚未将 position 属性的值从默认值 (static) 更改为未定位,因此 z-index 将无效。设置position: relative

    【讨论】:

    • 成功了!谢谢!
    猜你喜欢
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 2011-08-21
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 2022-01-23
    相关资源
    最近更新 更多