HTML – 如何在div上添加背景(灯箱效果)?

我正在编辑AngularJS项目,我想在用户点击搜索输入框时在主DIV上添加背景(如Bootstrap Modal).

《HTML – 如何在div上添加背景(灯箱效果)?》

这是HTML代码:

    <div class="main-box">
        <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>
    </div>

正如您所看到的,当用户单击搜索图标时会出现白色框,现在我想在主DIV上添加背景,白色框除外.

这是LESS代码:

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

.search-form {
  padding-left: 15%;
  padding-right: 15%;
  position: relative;
  z-index: 0;

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

我怎么能达到这个目的?

最佳答案 像这样的东西

 <div class="main-box">
    <div class="backdrop" ng-if="showForm"></div>
    <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>
</div>

并将CSS添加为

.backdrop {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: black;
    opacity: 0.5;
}
点赞