How to add background to div (lightbox effect)?

I am editing an AngularJS project and I want to add a background (e.g. Bootstrap Modal) on top of the main DIV when users click on the search input field.

enter image description here

Here is the HTML code:

    <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>

As you can see, a white frame appears when users click on the search icon, and now I want to add a background above the main DIV, except for the white one.

Here is the LESS code:

.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;
  }
}

How can i achieve this?

+4
source share
2 answers

Something like that

 <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>

And add CSS as

.backdrop {
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    background: black;
    opacity: 0.5;
}
+2
source

Here is a very complete article on the different methods of achieving what you need.

CSS overlay methods

0
source

All Articles